mercredi 26 août 2015

Display else results in Out-Gridview for powershell

I am trying to get a list of servers and the last time they rebooted to show in a table. However if it doesn't respond to a ping, I just need it to show on the list. I can't seem to figure out how to get it to add to the table after else.

Import-CSV $Downtime | % {
if(Test-Connection $_.server -Quiet -count 1){
    Get-WmiObject Win32_OperatingSystem -ComputerName $_.server | `
    select @{LABEL="Name"; EXPRESSION = {$_.PSComputerName}}, @{LABEL="Last Bootup"; EXPRESSION = {$_.convertToDateTime($_.LastBootupTime)}}
    }
else{@{LABEL="Name"; EXPRESSION = {$_.server}}
    }
} | Out-GridView

I can always save the else results in a text file but this would be more convenient. Thank you!

Aucun commentaire:

Enregistrer un commentaire