- 1 year ago
Listing system information in convenient format using Powershell
To list system information in a convenient format using PowerShell, you can utilize the Get-WmiObject
cmdlet and format the output as a table. Here's an example script that gathers common system information and displays it in a tabular format:
powershell# Get system information
$computerSystem = Get-WmiObject -Class Win32_ComputerSystem
$operatingSystem = Get-WmiObject -Class Win32_OperatingSystem
$processor = Get-WmiObject -Class Win32_Processor
# Create a custom object with system information
$systemInfo = [PSCustomObject] @{
'Hostname' = $computerSystem.Name
'Manufacturer' = $computerSystem.Manufacturer
'Model' = $computerSystem.Model
'Operating System' = $operatingSystem.Caption
'Version' = $operatingSystem.Version
'Architecture' = $processor.Architecture
'Processor' = $processor.Name
'Number of Cores' = $processor.NumberOfCores
'Total Physical Memory' = "{0:N2} GB" -f ($computerSystem.TotalPhysicalMemory / 1GB)
}
# Format and display the system information as a table
$systemInfo | Format-Table -AutoSize
This script retrieves information about the computer system, operating system, and processor using the Get-WmiObject
cmdlet. It then creates a custom object ($systemInfo
) with the gathered information. Finally, it uses Format-Table
to display the system information in a tabular format, automatically adjusting the column widths (-AutoSize
).
The output will include columns such as Hostname, Manufacturer, Model, Operating System, Version, Architecture, Processor, Number of Cores, and Total Physical Memory.
You can customize the script by adding or removing properties from the $systemInfo
object based on your specific requirements. Additionally, you can explore other WMI classes to gather additional system information if needed.