How can I stop and start individual websites in IIS using PowerShell?

前端 未结 4 1576
北荒
北荒 2020-12-13 01:57

I have multiple sites configured in IIS7 on my Windows 7 development machine to run on the same port and usually only run one at a time depending on what I\'m working on. I

4条回答
  •  旧巷少年郎
    2020-12-13 02:02

    Adding to Keith's answer, you can perform this remotely using Invoke-Command.

    Import-Module WebAdministration
    $siteName = "Default Web Site"
    $serverName = "name"
    $block = {Stop-WebSite $args[0]; Start-WebSite $args[0]};  
    $session = New-PSSession -ComputerName $serverName
    Invoke-Command -Session $session -ScriptBlock $block -ArgumentList $siteName 
    

提交回复
热议问题