I have the following script and it does well to give me systems that are online, and the reboot date/time:
#TYPE Selected.System.Management.ManagementObject
“csname”,“LastBootUpTime”
“LSLPC1762”,“6/10/2022 5:29:26 PM”
“LSLPC1994”,“7/11/2022 4:03:07 PM”
“LSLPC1743”,“6/14/2022 7:23:31 AM”
“LSLPC1802”,“6/29/2022 6:46:21 PM”
However, I would like to also list the systems that do not ping in the CSV report as well, such as “offline”. How do I do this?
Script:
Preformatted text
$machines = Get-Content “C:\Users\lslmea0\Desktop\Machine_List.txt”
$report = @()
$object = @()
foreach($machine in $machines)
{
$machine
if (Test-Connection -ComputerName $machine -Quiet -Count 1) {
$object = gwmi win32_operatingsystem -ComputerName $machine | select csname, @{LABEL=‘LastBootUpTime’;EXPRESSION={$.ConverttoDateTime($.lastbootuptime)}}
$report += $object
} else {
Write-Host “$machine is offline. Skipping…”
}
}
$report | Export-csv “C:\Users\lslmea0\Desktop\Reboot.csv”