需要幫助來創建腳本以獲取HPOA服務器刀片運行狀況報告 問題是,當我查詢健康狀況時,它會在PSO對象中輸出字段(IP,Health,Blades(@ {Blade1 。健康} {刀片2衛生} {3})) 我要像下面Excel報告在PowerShell中格式化
IP海灣發電衛生
報告 - --- -----
10.3。 131.2 1 On OK
2 On OK
3 On OK
4 On OK
5降級
變量如下導出。
$ sstaInfo = {} |選擇IP,灣,電力,衛生,DeviceFailure
$ sstaInfo.IP = $ ssta.IP(給出一個單一的IP輸出) $ sstaInfo.Bay = $ sstaBlades.Bay $ sstaInfo.Power = $ sstaBlades.Power $ sstaInfo .Health = $ sstaBlades.Health
我該如何得到這個工作?
$ ssta變量具有以下輸出: @ {Power = On; CurrentWattageUsed = 480;健康= OK; UnitIdentificationLED =關閉; VirtualFan = 33%; DiagnosticStatus =; Bay = 1} @ {Power = On; CurrentWattageUsed = 576;健康= OK; UnitIdentificationLED =關閉; VirtualFan = 47%; DiagnosticStatus =;灣= 2}
#------------------------------------------------------------ Input Variable Definations
$HPOAServers [email protected](
[pscustomobject]@{Name='10.11.12.13'},
[pscustomobject]@{Name='10.11.12.14'}
)
$Username ="admin"
$Password ="admin"
#------------------------------------------------------------ Main Script Starts Here
# Function for connecting to OA and returning connection object on success
foreach ($HPOAServer in $HPOAServers) {
$con = Connect-HPOA $HPOAServer.Name -username $Username -password $Password
$report = @()
$ssta = Get-HPOAServerStatus -Bay All $con
$sstaBlade=$ssta.Blade
Write-Host $sstaBlade
Foreach ($sstaBlades in $sstaBlade) {
$i++
$sstaInfo = {} | Select IP, Bay, Power, Health, DeviceFailure
$sstaInfo.IP=$ssta.IP
$sstaInfo.Bay=$sstaBlades.Bay
$sstaInfo.Power=$sstaBlades.Power
$sstaInfo.Health=$sstaBlades.Health
$sstaInfo.DeviceFailure=$ssta.Blade.DiagnosticStatus.DeviceFailure
}
$report += $ssta | Select-Object -Property IP
$report += $ssta.Blade | Select-Object -Property Bay, Power, Health | Format-Table *
$report | out-file "HPOA_Health_Report.txt" -Append
}
Disconnect-HPOA $con
上面的工作就像我的魅力:) –