每次我执行这个命令
invoke-command -computername REMOTEPC -scriptblock { import-module WebAdministration; new-item "$env:systemdrive\inetpub\testsite" -type directory; New-WebSite -Name TestSite -Port 81 -PhysicalPath "$env:systemdrive\inetpub\testsite" }
我得到以下错误
Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING)) + CategoryInfo : NotSpecified: (:) [Get-ChildItem], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.GetChildItemCommand
据我所知,该网站已成功创build。
枚举testsite时,下面的命令给出同样的错误
Invoke-Command -computername REMOTEPC { import-module webadministration; dir -path IIS:\Sites\ } Name ID State Physical Path Bindings PSComputerName Default Web Site 1 Started http *:80: REMOTEPC Invalid class string (Exception from HRESULT: 0x800401F3 (CO_E_CLASSSTRING)) + CategoryInfo : NotSpecified: (:) [Get-ChildItem], COMException + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.GetChildItemCo mmand
任何build议,将不胜感激
这是一个序列化问题。 来自IIS:\Sites\{sitename}协议的New-WebSite和顶级WebSite信息都返回Microsoft.IIs.PowerShell.Framework.Configurationtypes的对象。 该对象包含一个属性ftpServer ; 而ftpServer是不可序列化的。
来自IIS:\Sites\{siteName}\{subappname}协议的New-WebApplication和Sub-WebApplication信息没有ftpServer属性。 他们将不会有相同的序列化错误。
@CAD的解决scheme是伟大的,因为它阻止远程脚本返回任何对象。
但是,如果您想从远程机器返回网站信息,则可以使用:
$scriptBlock = { Import-Module WebAdministration $site = Get-Item IIS:\Sites\www.sitename.com $site.ftpServer = $null # this won't affect the real server value return $site } Invoke-Command -ComputerName REMOTEPC -ScriptBlock $scriptBlock
我和你有同样的问题。 我在迭代试图创build16个网站。 第一个正在创build,并有同样的例外…退出迭代和离开我只有一个创build的网站。 我没有修复它,但作为一个解决方法,我补充说
| 出空
在行的末尾。 这suppresed输出exception被忽略,我的迭代继续愉快。
就像是:
invoke-command -computername REMOTEPC -scriptblock { import-module WebAdministration; new-item "$env:systemdrive\inetpub\testsite" -type directory; New-WebSite -Name TestSite -Port 81 -PhysicalPath "$env:systemdrive\inetpub\testsite" | out-null}
(请注意,代码片段末尾的out-null)