Format-table combining results from multiple commands on same row

%3CLINGO-SUB%20id%3D%22lingo-sub-287102%22%20slang%3D%22en-US%22%3EFormat-table%20combining%20results%20from%20multiple%20commands%20on%20same%20row%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-287102%22%20slang%3D%22en-US%22%3E%3CP%3E(I'm%20new%20to%20PowerShell%20and%20my%20understanding%20is%20limited%20so%20I%20would%20appreciate%20a%20brief%20explanation%20as%20well%20as%20a%20solution%20if%20possible)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20got%20the%20following%20code%20running%20successfully%20to%20query%20a%20list%20of%20computers%20and%20return%20various%20data%20about%20them%20in%20a%20table.%26nbsp%3B%20However%2C%20the%20data%20from%20the%20various%20commands%20run%20against%20a%20particular%20computer%20is%20not%20appearing%20on%20the%20same%20row.%26nbsp%3B%20Can%20anyone%20suggest%20a%20way%20to%20combine%20the%20results%20for%20one%20machine%20onto%20a%20single%20table%20row%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CBLOCKQUOTE%3E%3CPRE%3E%24hostnames%20%3D%20Get-Content%20%22allpcs.txt%22%3CBR%20%2F%3E%3CBR%20%2F%3E%24output%20%3D%20foreach%20(%24hostname%20in%20%24hostnames)%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20(Test-Connection%20-ComputerName%20%24hostname%20-Count%201%20-ErrorAction%20'SilentlyContinue')%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Invoke-Command%20-ComputerName%20%24hostname%20-ScriptBlock%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Get-WmiObject%20Win32_ComputerSystem%20%7C%20Select-Object%20-ExcludeProperty%20name%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20(Get-ItemProperty%20-Path%20%22c%3A%5Cwindows%5Csystem32%5Chal.dll%22).VersionInfo.FileVersion%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20(Get-ItemProperty%20-Path%20%22C%3A%5CProgram%20Files%20(x86)%5CMicrosoft%20Office%5Croot%5COffice16%5CONENOTE.EXE%22).VersionInfo.FileVersion%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20gcim%20Win32_OperatingSystem%20%7C%20select%20InstallDate%2CLastBootupTime%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Get-PSDrive%20C%20%7C%20select%20Free%3B%20%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20else%20%7B%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20write-host%20%24hostname%20%22not%20connected%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%24output%20%7C%20Format-Table%20Name%2COSver%2CO365ver%2CInstallDate%2CLastBootupTime%2CFree%20%7C%20Out-File%20-filepath%20allpcs.csv%20-Append%3C%2FPRE%3E%3C%2FBLOCKQUOTE%3E%3CP%3EExample%20output%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EName%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20OSver%20O365ver%20InstallDate%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20LastBootupTime%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Free%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E----%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20-----%20-------%20-----------%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20--------------%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20----%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3Ecomp1%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E10.0.16299.371%20(WinBuild.160101.0800)%3CBR%20%2F%3E16.0.8431.2110%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%2005%2F10%2F2018%2016%3A18%3A59%2014%2F11%2F2018%2009%3A48%3A33%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%2040862683136%20%3CBR%20%2F%3Ecomp2%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E10.0.16299.371%20(WinBuild.160101.0800)%3CBR%20%2F%3E16.0.9126.2259%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%2013%2F08%2F2018%2015%3A49%3A28%2009%2F11%2F2018%2007%3A46%3A41%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20436695408640%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-287102%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EFormatting%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-324241%22%20slang%3D%22en-US%22%3ERe%3A%20Format-table%20combining%20results%20from%20multiple%20commands%20on%20same%20row%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-324241%22%20slang%3D%22en-US%22%3E%3CP%3EThank%20you%2C%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F256377%22%20target%3D%22_blank%22%3E%40Darrick%3C%2FA%3E%20the%20%3CA%20title%3D%22A%20PowerShell%20Object%20Lesson%3A%20Part%203%22%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fheyscriptingguy%2F2013%2F11%2F07%2Fa-powershell-object-lesson-part-3%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EA%20PowerShell%20Object%20Lesson%3A%20Part%203%3C%2FA%3E%20article%20was%20helpful.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20managed%20to%20tweak%20the%20code%20slightly%20to%20get%20my%20table%20by%20putting%20each%20new%20object%20into%20an%20array.%26nbsp%3B%20That%20array%20could%20then%20be%20presented%20as%20a%20table%20(and%20exported%20to%20csv).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20the%20final%2C%20working%20script%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24hostnames%20%3D%20Get-Content%20'allpcs.txt'%3CBR%20%2F%3E%3CBR%20%2F%3E%24allpcs%20%3D%20%40()%3CBR%20%2F%3E%3CBR%20%2F%3Eforeach%20(%24hostname%20in%20%24hostnames)%20%7B%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20if%20(Test-Connection%20-ComputerName%20%24hostname%20-Count%201%20-ErrorAction%20'SilentlyContinue')%20%7B%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%20%20%24OS%20%3D%20Get-WmiObject%20-Class%20Win32_OperatingSystem%20-Computer%20%24hostname%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%20%20%24pcinfo%20%3D%20%5BPSCustomObject%5D%40%7B%3CBR%20%2F%3E%26nbsp%3B%20%20%20%20%20Name%20%3D%20%24OS.PSComputerName%3CBR%20%2F%3E%26nbsp%3B%20%20%20%20%20OSVer%20%3D%20(Get-ItemProperty%20-Path%20'%5C%5C%24hostname%5Cc%24%5Cwindows%5Csystem32%5Chal.dll').VersionInfo.FileVersion%3CBR%20%2F%3E%26nbsp%3B%20%20%20%20%20O365ver%20%3D%20(Get-ItemProperty%20-Path%20'%5C%5C%24hostname%5Cc%24%5CProgram%20Files%20(x86)%5CMicrosoft%20Office%5Croot%5COffice16%5CONENOTE.EXE').VersionInfo.FileVersion%3B%3CBR%20%2F%3E%26nbsp%3B%20%20%20%20%20Free%20%3D%20Invoke-Command%20-ComputerName%20%24hostname%20%7B%5Bmath%5D%3A%3ARound((Get-PSDrive%20-Name%20C%20%7C%20Select-Object%20-ExpandProperty%20Free)%2F1GB%2C2)%7D%3CBR%20%2F%3E%26nbsp%3B%20%20%20%20%20InstallDate%20%3D%20%24OS.ConvertToDateTime(%24OS.Installdate)%3CBR%20%2F%3E%26nbsp%3B%20%20%20%20%20LastBootUpTime%20%3D%20%24OS.ConvertToDateTime(%24OS.LastBootUpTime)%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%20%20%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%20%20%24allpcs%20%2B%3D%20%24pcinfo%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20else%20%7B%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%20%20write-host%20%24hostname%20%22not%20connected%22%3CBR%20%2F%3E%26nbsp%3B%20%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3EWrite-Output%20%24allpcs%20%7C%20Format-Table%3CBR%20%2F%3EWrite-Output%20%24allpcs%20%7C%20ConvertTo-Csv%20%7C%20Out-File%20-filepath%20'allpcs.csv'%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-304793%22%20slang%3D%22en-US%22%3ERe%3A%20Format-table%20combining%20results%20from%20multiple%20commands%20on%20same%20row%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-304793%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESorry%2C%20I%20didn't%20have%20a%20chance%20to%20thoroughly%20test%20this%20yet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20you%20want%20is%20a%20PowerShell%20custom%20object%20to%20format%20the%20data%20the%20way%20you%20want.%20See%20below.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20may%20find%20this%20reference%20useful%3A%20%3CA%20title%3D%22A%20PowerShell%20Object%20Lesson%3A%20Part%203%22%20href%3D%22https%3A%2F%2Fblogs.technet.microsoft.com%2Fheyscriptingguy%2F2013%2F11%2F07%2Fa-powershell-object-lesson-part-3%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3EA%20PowerShell%20Object%20Lesson%3A%20Part%203%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E---------------------------------------------------------------------------------------------------%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24hostnames%20%3D%20Get-Content%20%22allpcs.txt%22%3CBR%20%2F%3E%3CBR%20%2F%3E%23%20create%20a%20custom%20PowerShell%20object%20to%20store%20specific%20information%3CBR%20%2F%3E%24ComputerInfoObj%20%3D%20%5BPSCustomObject%5D%40%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Name%20%3D%20%22%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20OSVer%20%3D%20%22%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20O365ver%20%3D%20%22%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20InstallDate%20%3D%20%22%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20LastBootUpTime%20%3D%20%22%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Free%20%3D%20%22%22%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%24output%20%3D%20foreach%20(%24hostname%20in%20%24hostnames)%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20if%20(Test-Connection%20-ComputerName%20%24hostname%20-Count%201%20-ErrorAction%20'SilentlyContinue')%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Invoke-Command%20-ComputerName%20%24hostname%20-ScriptBlock%20%7B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24ComputerInfoObj.Name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20(Get-WmiObject%20Win32_ComputerSystem).Name%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24ComputerInfoObj.OSVer%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20(Get-ItemProperty%20-Path%20%22c%3A%5Cwindows%5Csystem32%5Chal.dll%22).VersionInfo.FileVersion%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24ComputerInfoObj.O365ver%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20(Get-ItemProperty%20-Path%20%22C%3A%5CProgram%20Files%20(x86)%5CMicrosoft%20Office%5COffice16%5CONENOTE.EXE%22).VersionInfo.FileVersion%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24ComputerInfoobj.Free%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22%24(%5Bint64%5D((Get-PSDrive%20C).Free%20%2F%201GB))%20GB%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24ComputerInfoObj.InstallDate%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20(Get-CimInstance%20Win32_OperatingSystem).InstallDate%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%24ComputerInfoObj.LastBootUpTime%20%3D%20(Get-CimInstance%20Win32_OperatingSystem).LastBootUpTime%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%20%26nbsp%3B%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20else%20%7B%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20write-host%20%24hostname%20%22not%20connected%22%3CBR%20%2F%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3EWrite-OutPut%20%24ComputerInfoObj%20%7C%20Format-Table%3CBR%20%2F%3EWrite-Output%20%24ComputerInfoObj%20%7C%20ConvertTo-Csv%20%7C%20Out-File%20allpcs.csv%20-Append%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

(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

 

2 Replies

 

Sorry, I didn't have a chance to thoroughly test this yet.

 

What you want is a PowerShell custom object to format the data the way you want. See below.

 

You may find this reference useful: A PowerShell Object Lesson: Part 3

 

---------------------------------------------------------------------------------------------------

 

$hostnames = Get-Content "allpcs.txt"

# create a custom PowerShell object to store specific information
$ComputerInfoObj = [PSCustomObject]@{
    Name = ""
    OSVer = ""
    O365ver = ""
    InstallDate = ""
    LastBootUpTime = ""
    Free = ""
}


$output = foreach ($hostname in $hostnames) {
    
    if (Test-Connection -ComputerName $hostname -Count 1 -ErrorAction 'SilentlyContinue') {
    
        Invoke-Command -ComputerName $hostname -ScriptBlock {
            
            $ComputerInfoObj.Name           = (Get-WmiObject Win32_ComputerSystem).Name
            $ComputerInfoObj.OSVer          = (Get-ItemProperty -Path "c:\windows\system32\hal.dll").VersionInfo.FileVersion
            $ComputerInfoObj.O365ver        = (Get-ItemProperty -Path "C:\Program Files (x86)\Microsoft Office\Office16\ONENOTE.EXE").VersionInfo.FileVersion
            $ComputerInfoobj.Free           = "$([int64]((Get-PSDrive C).Free / 1GB)) GB"
            $ComputerInfoObj.InstallDate    = (Get-CimInstance Win32_OperatingSystem).InstallDate
            $ComputerInfoObj.LastBootUpTime = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
            
        }
    }
    
    else {

        write-host $hostname "not connected"
    }
}

Write-OutPut $ComputerInfoObj | Format-Table
Write-Output $ComputerInfoObj | ConvertTo-Csv | Out-File allpcs.csv -Append

Highlighted

Thank you, @Darrick the A PowerShell Object Lesson: Part 3 article was helpful.

 

I managed to tweak the code slightly to get my table by putting each new object into an array.  That array could then be presented as a table (and exported to csv).

 

Here is the final, working script:

 

$hostnames = Get-Content 'allpcs.txt'

$allpcs = @()

foreach ($hostname in $hostnames) {

  if (Test-Connection -ComputerName $hostname -Count 1 -ErrorAction 'SilentlyContinue') {

  $OS = Get-WmiObject -Class Win32_OperatingSystem -Computer $hostname

  $pcinfo = [PSCustomObject]@{
  Name = $OS.PSComputerName
  OSVer = (Get-ItemProperty -Path '\\$hostname\c$\windows\system32\hal.dll').VersionInfo.FileVersion
  O365ver = (Get-ItemProperty -Path '\\$hostname\c$\Program Files (x86)\Microsoft Office\root\Office16\ONENOTE.EXE').VersionInfo.FileVersion;
  Free = Invoke-Command -ComputerName $hostname {[math]::Round((Get-PSDrive -Name C | Select-Object -ExpandProperty Free)/1GB,2)}
  InstallDate = $OS.ConvertToDateTime($OS.Installdate)
  LastBootUpTime = $OS.ConvertToDateTime($OS.LastBootUpTime)

  }

  $allpcs += $pcinfo

  }

  else {

  write-host $hostname "not connected"
  }
}

Write-Output $allpcs | Format-Table
Write-Output $allpcs | ConvertTo-Csv | Out-File -filepath 'allpcs.csv'