Roi*_*ise 2 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()
# SIG # Begin signature block ...
Run Code Online (Sandbox Code Playgroud)
但是当我在具有高安全性策略的服务器上运行脚本时,我收到此错误:
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
Run Code Online (Sandbox Code Playgroud)
从我所看到的,如果我无法访问IIS,可能会发生这种情况,但我以管理员身份运行脚本,是否应该授予我所需的访问权限?
Web管理模块是否提供更多访问权限?我不导入这个,因为我没有必要在其他服务器上执行此操作,如果我需要导入webadministration还有另一个问题,当我尝试我得到一个错误说WebAdministrationAliases.ps1没有数字签名.. .
我已经在其他服务器上测试了这个脚本没有问题,但是如上所述,这个策略有更严格的策略,而且它不是更改策略的选项.
我使用IIS 7.5在Windows Server 2008 R2上运行此功能.
Import-Module WebAdministration
Stop-WebSite 'Default Web Site'
Start-WebSite 'Default Web Site'
Run Code Online (Sandbox Code Playgroud)
基于大卫的回答:
在最新版本的 Windows(10、2016 及更高版本)中,您需要导入 IISAdministration 而不是 WebAdministration
Import-Module IISAdministration
Stop-WebSite 'Default Web Site'
Start-WebSite 'Default Web Site'
Run Code Online (Sandbox Code Playgroud)
对于旧版本的 Windows 和 IIS,您需要执行以下操作
Import-Module WebAdministration
Stop-WebSite 'Default Web Site'
Start-WebSite 'Default Web Site'
Run Code Online (Sandbox Code Playgroud)
阅读更多:
2- https://blogs.iis.net/iisteam/introducing-iisadministration-in-the-powershell-gallery
| 归档时间: |
|
| 查看次数: |
7011 次 |
| 最近记录: |