Need help for this report!

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”

Frederick,
Welcome to the forum. :wave:t4:

Before we proceed … please go back and fix the formatting of your question.

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org <---- Click :point_up_2:t4: :wink:

1 Like