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 would like to be able to start and stop my development sites from PowerShell instead of having the IIS manager opened. Does anyone have a good resource to point me in the right direction or a script that already accomplishes this?
Just for future quick reference, the commands are:
Import-Module WebAdministration
Stop-WebSite 'Default Web Site'
Start-WebSite 'Default Web Site'
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
To get access to system modules, Powershell needs to be run like this:
[path]\powershell.exe -NoExit -ImportSystemModules
I found the above on this iis forum .
I found that the following to stop individual websites on a remote server to work:
Invoke-Command -Computername $servername -Scriptblock {
(Import-Module WebAdministration);
Stop-Website -Name "WebsiteName";
Stop-Website -Name "AnotherWebsiteName"
}
I had some of the errors above until Import-Module
was put in ()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.