[英]How to get all (IIS) websites status/state from remote machine using PowerShell?
我试图从远程读取IIS网站的状态。 我试过下面的代码。
$Session = New-PSSession -ComputerName $serverName
$block = {
import-module 'webAdministration'
Get-ChildItem -path IIS:\Sites
}
Invoke-Command -Session $Session -ScriptBlock $block | Out-File -append $WebreportPath
但是上面的命令只给了我带有https绑定的网站,当涉及到https时它会抛出错误。
The data is invalid. (Exception from HRESULT: 0x8007000D)
+ CategoryInfo : NotSpecified: (:) [Get-ChildItem], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException,Microsoft.PowerShell.Commands.GetChildItemCommand
我正在尝试使用IIS 7升级Windows Server 2008 R2。请指导我。 谢谢 !
希望这对某人有所帮助。 以下是我的发现和答案。
Powershell仅远程发送对象,并使用可用模板呈现它们。 所以需要相应地给出一个模板。 我用了“格式表”。 请注意,如果在其外使用“格式表”,则会产生相同的错误。 记得在scriptblock中使用它。
容易出错:
Invoke-Command -ComputerName $serverName { Import-Module WebAdministration; Get-ChildItem -path IIS:\Sites} | Format-Table | Out-File -append $WebreportPath
正确的代码:
Invoke-Command -ComputerName $serverName { Import-Module WebAdministration; Get-ChildItem -path IIS:\Sites | Format-Table} | Out-File -append $WebreportPath
我指的是: http : //forums.iis.net/t/1155059.aspx?IIS + provider+and+PowerShell+remoting
祝好运 !
使用远程会话检索对象似乎存在一些问题,但这不是阻塞问题(我也遇到过此问题)。
要防止写入错误,可以使用-ErrorAction
如下所示:
$Session = New-PSSession -ComputerName $serverName
$block = {
Import-Module 'webAdministration'
Get-ChildItem -path IIS:\Sites
}
Invoke-Command -Session $Session -ErrorAction SilentlyContinue -ScriptBlock $block |
Out-File -append $WebreportPath
这样您就不会看到远程处理错误,但仍会收到所需的数据。
请注意,这会隐藏所有错误,因此您可能隐藏了您可能想要查看的错误。 为此,您需要修复底层ptoblem,因此您可以删除-ErrorAction
补丁。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.