术语 'Get-WebBinding' 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称

The term 'Get-WebBinding' is not recognized as the name of a cmdlet, function, script file, or operable program

在 Powershell 中的服务器 2008 R2 Standard 上。我正在尝试 运行 使用 Get-WebBinding

的脚本
try{
Import-Module WebAdministration
Get-WebApplication

$webapps = Get-WebApplication
$list = @()
foreach ($webapp in get-childitem IIS:\AppPools\)
{
$name = "IIS:\AppPools\" + $webapp.name
$item = @{}

$item.WebAppName = $webapp.name
$item.Version = (Get-ItemProperty $name managedRuntimeVersion).Value
$item.State = (Get-WebAppPoolState -Name $webapp.name).Value
$item.UserIdentityType = $webapp.processModel.identityType
$item.Username = $webapp.processModel.userName
$item.Password = $webapp.processModel.password

$obj = New-Object PSObject -Property $item
$list += $obj
}

$list | Format-Table -a -Property "WebAppName", "Version", "State", "UserIdentityType", "Username", "Password" | Out-String

}catch
{
$ExceptionMessage = "Error in Line: " + $_.Exception.Line + ". " + $_.Exception.GetType().FullName + ": " + $_.Exception.Message + " Stacktrace: " + $_.Exception.StackTrace
$ExceptionMessage
}

但是,我收到以下错误:

The term 'Get-WebBinding' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:25 char:15 + Get-WebBinding <<<< | % { + CategoryInfo : ObjectNotFound: (Get-WebBinding:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

我尝试添加管理单元并遇到此错误:

PS C:\Windows\system32> add-pssnapin WebAdministration Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2. At line:1 char:13 + add-pssnapin <<<< WebAdministration + CategoryInfo : InvalidArgument: (WebAdministration:String) [Add-PSSnapin], PSArgumentException + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

根据这篇文章 https://community.spiceworks.com/topic/370385-powershell-commands-to-export-iis7-sites-binding-information: since I am using iis 7, I tried to get the powershell extensions. I went to the iis.net link ( https://www.iis.net/downloads/microsoft/powershell ) 找不到下载。该按钮只会将您带到图库搜索。

有一个安装扩展的按钮,但它不会拉出安装程序。

Set-ExecutionPolicy RemoteSigned 然后重启 Powershell 解决了我的问题。