Hi Experts,
I’m relatively new to Powershell and I’m having some problems getting things to output in the format that I want. I have created the code below to run through a list of servers, determine the last reboot time, and if a server is pending a reboot. Right now it works alright and outputs to the screen. However it would be nice to also have it output to a CSV and/or out-gridview. Maybe out-gridview isn’t the way to do it, but I just learned about it and wanted to try and play with it.
My problem was when I tried to use out-gridview it would open a new window for each server and object. How do I get all of the servers and information from each time it executes the loop to output to the same window? Is there a way to append to an existing gridview window? Do i need to collate everything before outputting to out-gridview?
foreach ($server in get-content "./serversTEST.txt")
{
#loop through each server and check last reboot and reboot pending status
Write-Host "$server rebooted last" -BackgroundColor DarkBlue -ForegroundColor Yellow
$wmi = Get-WmiObject -Class Win32_OperatingSystem -Computer "$server"
$wmi.ConvertToDateTime($wmi.LastBootUpTime)
$reboot = [wmiclass]"\\$server\root\ccm\ClientSDK:CCM_ClientUtilities"
$result = $reboot.DetermineIfRebootPending() | Select RebootPending
If ($result -like '@{RebootPending=False}')
{Write-Host $result -ForegroundColor Green}
Else
{Write-Host $result -ForegroundColor Red}
Write-Host "" ----------------------------------------
}
If somebody could help me over my hurdle and get me on my way to better understanding I would greatly appreciate it.
Thanks,
Brett