windows 如何使用 PowerShell 在 IIS 中停止和启动单个网站?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2710166/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I stop and start individual websites in IIS using PowerShell?
提问by Joey Green
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?
我在 Windows 7 开发机器上的 IIS7 中配置了多个站点以在同一端口上运行,并且通常一次只运行一个站点,具体取决于我正在处理的内容。我希望能够从 PowerShell 启动和停止我的开发站点,而不是打开 IIS 管理器。有没有人有很好的资源来为我指出正确的方向或已经完成此任务的脚本?
回答by Keith Hill
Just for future quick reference, the commands are:
仅供将来快速参考,命令是:
Import-Module WebAdministration
Stop-WebSite 'Default Web Site'
Start-WebSite 'Default Web Site'
回答by Tim
Adding to Keith's answer, you can perform this remotely using Invoke-Command.
添加到 Keith 的答案中,您可以使用 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
回答by Patrick S.
回答by Russ
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 ()
我有上面的一些错误,直到Import-Module
被放入()