2012-02-24 58 views
1

我正在使用PSRemoting与Web管理模块获取有关各个站点的信息,并且它正在工作。然而,我在调用该命令期间接收到一个烦人的非致命COM异常,并想知道是否有其他人解决了它。这里有一个最小的实现:PowerShell IIS: WebAdmin远程调用触发器WSAStartup错误,WSANOTINITIALISED

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 

我观察的结果被抛出错误之前返回。

好玩的细节:
- 获取-网站,获取项目 “IIS:\ ...”,则Get-WebBinding都会导致同样的错误
- 直接在目标计算机上运行$命令,以书面结果没有错误
- 获取项目“d:\ ...”不会导致任何错误
- 的COM错误不

+0

我从PowerGUI的和Powershell命令提示符和对2台不同的目标服务器3级独立的服务器W2K8运行这段代码。在所有情况下,我都收到了同样的错误。 – codepoke 2012-02-24 16:27:38

+0

有趣的是,NetMon显示与/ wsman的加密对话在失败的WebAdmin会话和“成功”的Get-Item'd:\'会话之间非常相似。这两个会话都以远程服务器发回加密数据结束,然后(到最后一个帖子,理论上断开请求?)500内部服务器错误。没有真正的信息,因为我无法解密对话,但很有趣。 – codepoke 2012-02-24 18:39:17

+0

由于我处于详细模式,因此我将添加这个内容非常重要,因为我的内部客户端会看到错误并困扰我。为此,直到找到真正的解决方案,我在远程调用中添加了“-ErrorAction SilentlyContinue”。它处理这个问题。 – codepoke 2012-02-24 18:45:50

回答

0

这是什么地方深深地埋在PowerShell的执行.NET的肠子和winsock的。它低于我可以校准的任何东西,所以我在远程调用中添加了“-ErrorAction SilentlyContinue”。它不能解决任何问题,但一切正常。我想现在这个答案已经足够了。

2

我能够用解决问题如下:

$iisIpAddresses = Invoke-Command -Session $session -scriptblock { 
    if (!(Get-Module WebAdministration)) 
    { 
     Import-Module WebAdministration 
    } 
    $iisBindings = Get-WebBinding 
    [String[]]$iisBindings = $iisBindings | Select bindingInformation 
    $iisBindings 
} 

Remove-PSSession $session