Iis 正在使用powerShell脚本停止网站

Iis 正在使用powerShell脚本停止网站,iis,powershell,windows-server-2008,Iis,Powershell,Windows Server 2008,我有一个停止网站的脚本: param($HostName = "localhost", $SiteName) $server = $HostName $siteName = $SiteName $iis = [ADSI]"IIS://$server/W3SVC" $site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND $_.ServerComment -eq $siteName} $site.start

我有一个停止网站的脚本:

param($HostName = "localhost", $SiteName)

$server = $HostName
$siteName = $SiteName
$iis = [ADSI]"IIS://$server/W3SVC"
$site = $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND $_.ServerComment -eq $siteName}
$site.start()

# SIG # Begin signature block ...
但是,当我在具有高安全策略的服务器上运行脚本时,会出现以下错误:

The following exception was thrown when trying to enumerate the collection: "Unknown error (0x80005000)".
At D:\DeploymentScripts\Common\StopSite.ps1:6 char:8
+ $site = <<<<  $iis.psbase.children | where { $_.keyType -eq "IIsWebServer" -AND $_.ServerComment -eq $siteName}
    + CategoryInfo          : NotSpecified: (:) [], ExtendedTypeSystemException
    + FullyQualifiedErrorId : ExceptionInGetEnumerator
尝试枚举集合时引发以下异常:“未知错误(0x80005000)”。
位于D:\DeploymentScripts\Common\StopSite.ps1:6 char:8

+$site=根据David的回答:

在最新版本的Windows(10、2016及更高版本)中,您需要导入IISAdministration而不是WebAdministration

Import-Module IISAdministration
Stop-WebSite 'Default Web Site'
Start-WebSite 'Default Web Site'
对于旧版本的Windows和IIS,您需要执行以下操作

Import-Module WebAdministration
Stop-WebSite 'Default Web Site'
Start-WebSite 'Default Web Site'
阅读更多:

1-


2-

你试过这个吗?签出。您链接到的powershell iis模块是iss 7.0的管理单元,我使用的是使用模块的7.5,并且该iis模块不是与webadmin模块相同吗?它也适用于iis 7.5,尝试安装该管理单元,但它说当前操作系统不支持该管理单元。我对“导入模块WebAdministration”如果我运行它,它会说它已导入:,但如果我运行:“导入模块-名称WebAdministration”,我会收到未经数字签名的错误。停止网站未被识别为命令执行策略是什么(get ExecutionPolicy)?在调用import-module之前,您可能应该将其设置为适当的级别。我的执行策略是AllSignedTry“set ExecutionPolicy Unrestricted”“,然后尝试导入webadministration模块。我使用RemoteSigned now进行了测试,结果显示,按照我对此答案的第一条评论中所述,默认导入了该模块。所以这排除了我的网络管理包理论。。。
Import-Module WebAdministration
Stop-WebSite 'Default Web Site'
Start-WebSite 'Default Web Site'