2017-05-04 73 views
1

需要幫助來創建腳本以獲取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 

回答

0
Function HPOA() { 
try 
{ 
     Remove-Item -Path $outputfile -Force 
     foreach ($HPOAServer in $HPOAServers) 
     { 
      $con = Connect-HPOA $HPOAServer.Name -username $Username -password $Password -ErrorAction 'Stop' 
      $ssta = Get-HPOAServerStatus -Bay All $con 

     $ssta.Blade | Foreach-Object { 
     $sstaInfo = $_ 

     $sstaInfo | Select-Object -Property @{Name="Chassis_IP_Address";Expression={$ssta.IP}}, 
      @{Name="Blade_Power_Status";Expression={$_.Power}}, 
      @{Name="Blade_Bay_Number";Expression={$_.Bay}}, 
      @{Name="Blade_Health_Status";Expression={$_.Health}}, 
      @{Name="Blade_Diagnostic_DeviceFailure_Status";Expression={$ssta.Blade.DiagnosticStatus.DeviceFailure}} 

     } | ConvertTo-Html -Title " $HPOARegionName HPOA Health Report " -Head $Header -Body "<H2> $HPOARegionName HPOA Health Report </H2>" -As Table | Out-File -Append $outputfile 
     Disconnect-HPOA $con 
    } 


} 

catch 
{ 
    $ErrorMessage = $_.Exception.Message 
    $FailedItem = $_.Exception.ItemName 
    Write-Host $ErrorMessage 
    Write-Host $FailedItem 

} 

} 

HPOA 
+0

上面的工作就像我的魅力:) –

1

我建議你使用出口爲CSV代替,所以下面一行

$report | Out-File "HPOA_Health_Report.txt" -Append 

將被替換爲:

$report | Export-Csv "HPOA_Health_Report.csv" -Append -NoTypeInformation 
+0

這不起作用,給人一個空白輸出 –