首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell IIS:\ WebAdmin远程调用触发WSAStartup错误,WSANOTINITIALISED

PowerShell IIS:\ WebAdmin远程调用触发WSAStartup错误,WSANOTINITIALISED
EN

Stack Overflow用户
提问于 2012-02-25 00:00:14
回答 2查看 1.5K关注 0票数 2

我正在使用带有WebAdministration模块的PSRemoting来获取各种站点的信息,并且它正在工作。然而,在调用命令的过程中,我收到了一个恼人的非致命COM异常,并且想知道是否有人已经解决了这个问题。下面是一个最小的实现:

代码语言:javascript
复制
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")
}

结果如下:

代码语言:javascript
复制
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

我观察到结果是在抛出错误之前返回的。

有趣的细节:

  • Get-Website,Get-IIS "IIS:...",Get-WebBinding all会导致
  • 直接在目标计算机上运行$command时出现相同的错误,这与写入的错误
  • Get-Item "d:...“中的结果相同The COM error

不会导致任何错误

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-01-18 05:52:16

这深藏在PowerShell的.NET和winsock实现中的某个地方。它低于我能校准的任何值,所以我在远程调用中添加了“-ErrorAction SilentlyContinue”。它不能修复任何东西,但一切都能正常工作。我想,这就是现在的答案。

票数 0
EN

Stack Overflow用户

发布于 2013-02-27 05:28:38

我可以使用以下方法来解决这个问题:

代码语言:javascript
复制
    $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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9433886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档