Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 979
Joey Green Avatar asked Apr 25 '10 22:04

Joey Green


People also ask

How do I stop a website from PowerShell using IIS?

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.

How do I stop a website from command line using IIS?

The Stop-IISSite cmdlet stops an existing site on the Internet Information Services (IIS) server.


2 Answers

Just for future quick reference, the commands are:

Import-Module WebAdministration Stop-WebSite 'Default Web Site' Start-WebSite 'Default Web Site' 
like image 135
Keith Hill Avatar answered Oct 03 '22 08:10

Keith Hill


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  
like image 21
Tim Avatar answered Oct 03 '22 09:10

Tim