PowerShell Script to Generate System Report Easily
Get-ComputerInfo | Select-Object CsName, OsName, OsVersion, CsProcessors, CsTotalPhysicalMemory | Format-List to generate a simple system report showing computer name, OS, CPU, and memory details.Examples
How to Think About It
Algorithm
Code
Get-ComputerInfo | Select-Object CsName, OsName, OsVersion, CsProcessors, CsTotalPhysicalMemory | Format-List
Dry Run
Let's trace running the script on a Windows 10 PC named DESKTOP-12345.
Get system info
Get-ComputerInfo returns all system properties including CsName=DESKTOP-12345, OsName=Microsoft Windows 10 Pro, OsVersion=10.0.19044, CsProcessors={Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz}, CsTotalPhysicalMemory=17179869184
Select properties
Select-Object picks CsName, OsName, OsVersion, CsProcessors, CsTotalPhysicalMemory from the full info
Format output
Format-List displays the selected properties in a readable list format
| Step | Action | Value |
|---|---|---|
| 1 | Get-ComputerInfo | CsName=DESKTOP-12345, OsName=Microsoft Windows 10 Pro, OsVersion=10.0.19044, CsProcessors=Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz, Memory=17179869184 |
| 2 | Select-Object | CsName, OsName, OsVersion, CsProcessors, CsTotalPhysicalMemory |
| 3 | Format-List | Formatted list output |
Why This Works
Step 1: Gather system data
The Get-ComputerInfo cmdlet collects detailed system information from the computer.
Step 2: Choose relevant details
Using Select-Object, we pick only the important properties to keep the report clear and focused.
Step 3: Format for readability
Format-List arranges the output vertically so each property is easy to read.
Alternative Approaches
Get-WmiObject -Class Win32_OperatingSystem | Select-Object CSName, Caption, Version, BuildNumber
Get-ComputerInfo | Select CsName, OsName, OsVersion, CsProcessors, CsTotalPhysicalMemory | Format-List | Out-File system_report.txt
Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Name, Manufacturer, Model, TotalPhysicalMemory
Complexity: O(1) time, O(1) space
Time Complexity
The script runs in constant time because it queries fixed system properties once without loops.
Space Complexity
Uses constant space to hold system info objects; no large data structures are created.
Which Approach is Fastest?
Using Get-ComputerInfo is fast and comprehensive; CIM cmdlets are also efficient for hardware info.
| Approach | Time | Space | Best For |
|---|---|---|---|
| Get-ComputerInfo | O(1) | O(1) | Full system info, easy to use |
| Get-WmiObject | O(1) | O(1) | Legacy systems, OS details |
| Get-CimInstance | O(1) | O(1) | Hardware info, modern cmdlets |
Format-List to make system info output easier to read in PowerShell.