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?
To stop an IIS website, you will use the Stop-IISSite cmdlet. By default, the site that you created earlier should be in a Started state.
The Stop-IISSite cmdlet stops an existing site on the Internet Information Services (IIS) server.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With