I have a script that reads from a list of computers, does a test connection. If it gets a reply from the Test-Connection
, it does a if/else and builds a variabl
Expand the IP address:
... | Select-Object -Expand IPV4Address | Select-Object -Expand IPAddressToString
and don't turn the directory information into a string:
$Details = "$LastUserLoggedIn"
Build your data object like this:
$obj = [PSCustomObject]@{
SystemName = $Computername
IPV4Address = $ipreachable
UserName = $LastUserLoggedIn.Name
Timestamp = $LastUserLoggedIn.LastWriteTime
}
So that you can display the information on the console as well as export it to a CSV:
$obj | Format-Table -AutoSize
$obj | Export-Csv 'C:\path\to\your.csv' -NoType -Append