【问题标题】:Stopping website with powerShell script使用 powerShell 脚本停止网站
【发布时间】:2012-05-11 07:21:43
【问题描述】:

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

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

从我读到的内容来看,如果我无法访问 IIS,但我以管理员身份运行脚本,这可能不会授予我所需的访问权限吗?

webadministration 模块是否提供更多访问权限? 我不导入它,因为我不必在其他服务器上执行此操作,如果我需要导入 webadministration 还有另一个问题,当我尝试时我收到错误消息说 WebAdministrationAliases.ps1 没有数字签名.. .

我已经在其他服务器上测试了脚本没有问题,但是这个脚本如上所述有更严格的策略,并且它不是更改策略的选项。

我在带有 IIS 7.5 的 Windows 服务器 2008 R2 上运行它。

【问题讨论】:

  • 你试过PowerShell IIS module吗?查看Stop-Website
  • 您链接到的 powershell iis 模块是 iss 7.0 的管理单元,我使用的是使用模块的 7.5,而 iis 模块与 webadmin 模块不一样吗?
  • 同样适用于IIS 7.5,learn.iis.net/page.aspx/429/…
  • 尝试安装管理单元,但提示当前操作系统不支持

标签: iis powershell windows-server-2008


【解决方案1】:
Import-Module WebAdministration
Stop-WebSite 'Default Web Site'
Start-WebSite 'Default Web Site'

【讨论】:

  • 我在运行“Import-Module WebAdministration”时遇到问题,如果我运行它说它已经导入:link,但如果我运行:“Import-Module -Name webadministration”我得到没有数字签名的错误。并且 Stop-WebSite 不被识别为命令
  • 你的执行策略是什么(Get-ExecutionPolicy)?您可能应该在调用 import-module 之前将其设置为适当的级别。
  • 我的执行策略是AllSigned
  • 尝试“Set-ExecutionPolicy Unrestricted”,然后尝试导入 webadministration 模块。
  • 我现在用 RemoteSigned 进行了测试,消息是它的默认导入,如我对该答案的第一条评论中所述。所以这排除了我的网络管理包理论......
【解决方案2】:

根据大卫的回答:

在最新版本的 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-https://docs.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/iisadministration-powershell-cmdlets

2-https://blogs.iis.net/iisteam/introducing-iisadministration-in-the-powershell-gallery

【讨论】:

    猜你喜欢
    • 2020-03-09
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-20
    相关资源
    最近更新 更多