我正在使用带有WebAdministration模块的PSRemoting来获取各种站点的信息,并且它正在工作。然而,在调用命令的过程中,我收到了一个恼人的非致命COM异常,并且想知道是否有人已经解决了这个问题。下面是一个最小的实现:
cls
$command = {
param($alias)
Import-Module 'WebAdministration'
$binding = Get-WebBinding -HostHeader $alias
$binding
}
$server = 'server'
$args = @('alias')
$session = New-PSSession -ComputerName $server
Write-Host ("Invoking")
try {
Invoke-Command -Session $session -ScriptBlock $command -ArgumentList $args
Write-Host ("Invoked")
} catch {
Write-Host ("Caught $_")
} finally {
Write-Host ("Removing")
Remove-PSSession -Session $session
Write-Host ("Removed")
}结果如下:
Invoking
protocol : http
bindingInformation : 10.x.x.x:80:alias
...
Schema : Microsoft.IIs.PowerShell.Framework.ConfigurationElementSchema
An unhandled COM interop exception occurred: Either the application has not called WSAStartup, or WSAStartup failed. (Exception from HRESULT: 0x800
7276D)
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : COMException
Invoked
Removing
Removed我观察到结果是在抛出错误之前返回的。
有趣的细节:
不会导致任何错误
发布于 2013-01-18 05:52:16
这深藏在PowerShell的.NET和winsock实现中的某个地方。它低于我能校准的任何值,所以我在远程调用中添加了“-ErrorAction SilentlyContinue”。它不能修复任何东西,但一切都能正常工作。我想,这就是现在的答案。
发布于 2013-02-27 05:28:38
我可以使用以下方法来解决这个问题:
$iisIpAddresses = Invoke-Command -Session $session -scriptblock {
if (!(Get-Module WebAdministration))
{
Import-Module WebAdministration
}
$iisBindings = Get-WebBinding
[String[]]$iisBindings = $iisBindings | Select bindingInformation
$iisBindings
}
Remove-PSSession $sessionhttps://stackoverflow.com/questions/9433886
复制相似问题