Q. How can I have my PowerShell script display output in a table?Q. How can I have my PowerShell script display output in a table?
Let's say you want your script to retrieve and display two pieces of information—the BIOS serial number and Windows version—it in a table.
Don Jones
July 14, 2010
1 Min Read
Q. How can I have my PowerShell script display output in a table?
A. Let's say you want your script to retrieve and display two pieces of information—the BIOS serial number and Windows version—it in a table. The key is to output that information on a custom object:
$os = gwmi win32_operatingsystem$bios = gwmi win32_bios$obj = new-object psobject$obj | add-member noteproperty OSBuild ($os.buildnumber)$obj | add-member noteproperty BIOSSerial ($bios.serialnumber)write-output $obj
Doing so opens up a bunch of output possibilities. Let's say all that was contained in a file named C:Get-Info.ps1:
C:Get-Info | Out-GridViewC:Get-Info | Export-CSV Info.csvC:Get-Info | Format-Table -autosize
You can do anything with script output if it's in the form of objects.
Do you have a Windows PowerShell question? Find more PowerShell FAQs, articles, and other resources at windowsitpro.com/go/DonJonesPowerShell.
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like