So I have this script working except I cannot get the computer name to display when there is an error, I understand that is because the computer is offline and the first Get computername cmd is an error as well, but I have tried multiple ways to perform this function with one thing or another not working.
gc "\\server\s$\powershellscripts\LabMachines\*.txt" | ForEach-Object{
Try{
$wdt = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $_ -Ea Stop
$cdt = Get-Content "\\$_\C$\file\*.txt" -Ea Stop
}
Catch{
$wdt= $_
$cdt = 'Offline or NoFile'
}
$wdt | Select @{n='WorkStation';e={$_.PSComputerName}},@{n='Version';e={$cdt}}
} | ogv -Title 'Versions'
$host.enternestedprompt()
In a different attempt I have used this script, but this one below formats the information in rows instead of column like the first one.
Get-Content "\\server\s$\powershellscripts\LabMachines\*.txt" | ForEach-Object {
Try{
@{ComputerName=$_}
@{Version = Get-Content "\\$_\C$\file\*.txt" -Ea Stop}
}
Catch{
@{Version = 'Offline or NoFile' }
}
} #| out-file \\localhost\c$\users\public\Desktop\version.csv
Any attempt to take my script and merge it with one someone suggested to me "the second one" breaks it completely. To reiterate the top script give me the format output in columns I want but the bottom script gives the catch error "ComputerName Error" I need but has the output in harder to read row outfile.
Any suggestions? Thanks.
$PSVersionTable
)? – Mathias R. Jessen