Reinier SPRUIJT
Nov 15, 2018Brass Contributor
Format-table combining results from multiple commands on same row
(I'm new to PowerShell and my understanding is limited so I would appreciate a brief explanation as well as a solution if possible)
I've got the following code running successfully to query a list of computers and return various data about them in a table. However, the data from the various commands run against a particular computer is not appearing on the same row. Can anyone suggest a way to combine the results for one machine onto a single table row?
$hostnames = Get-Content "allpcs.txt"
$output = foreach ($hostname in $hostnames) {
if (Test-Connection -ComputerName $hostname -Count 1 -ErrorAction 'SilentlyContinue') {
Invoke-Command -ComputerName $hostname -ScriptBlock {
Get-WmiObject Win32_ComputerSystem | Select-Object -ExcludeProperty name;
(Get-ItemProperty -Path "c:\windows\system32\hal.dll").VersionInfo.FileVersion;
(Get-ItemProperty -Path "C:\Program Files (x86)\Microsoft Office\root\Office16\ONENOTE.EXE").VersionInfo.FileVersion;
gcim Win32_OperatingSystem | select InstallDate,LastBootupTime;
Get-PSDrive C | select Free;
}
}
else {
write-host $hostname "not connected"
}
}
$output | Format-Table Name,OSver,O365ver,InstallDate,LastBootupTime,Free | Out-File -filepath allpcs.csv -Append
Example output:
Name OSver O365ver InstallDate LastBootupTime Free
---- ----- ------- ----------- -------------- ----
comp1
10.0.16299.371 (WinBuild.160101.0800)
16.0.8431.2110
05/10/2018 16:18:59 14/11/2018 09:48:33
40862683136
comp2
10.0.16299.371 (WinBuild.160101.0800)
16.0.9126.2259
13/08/2018 15:49:28 09/11/2018 07:46:41
436695408640