[英]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.