0
0
PowershellHow-ToBeginner · 2 min read

PowerShell Script to Generate System Report Easily

Use the PowerShell script 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

InputRun script on Windows 10 PC
OutputCsName : DESKTOP-12345 OsName : Microsoft Windows 10 Pro OsVersion : 10.0.19044 CsProcessors : {Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz} CsTotalPhysicalMemory : 17179869184
InputRun script on Windows Server 2019
OutputCsName : SERVER01 OsName : Microsoft Windows Server 2019 Standard OsVersion : 10.0.17763 CsProcessors : {Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz} CsTotalPhysicalMemory : 34359738368
InputRun script on Windows 11 laptop
OutputCsName : LAPTOP-67890 OsName : Microsoft Windows 11 Pro OsVersion : 10.0.22000 CsProcessors : {AMD Ryzen 7 5800U} CsTotalPhysicalMemory : 17179869184
🧠

How to Think About It

To create a system report, gather key system information like computer name, operating system details, processor info, and memory size. Use PowerShell cmdlets to fetch this data and format it for easy reading.
📐

Algorithm

1
Get system information using built-in PowerShell cmdlets.
2
Select relevant properties such as computer name, OS name, OS version, processor details, and total physical memory.
3
Format the selected information into a readable list.
4
Output the formatted system report to the console.
💻

Code

powershell
Get-ComputerInfo | Select-Object CsName, OsName, OsVersion, CsProcessors, CsTotalPhysicalMemory | Format-List
Output
CsName : DESKTOP-12345 OsName : Microsoft Windows 10 Pro OsVersion : 10.0.19044 CsProcessors : {Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz} CsTotalPhysicalMemory : 17179869184
🔍

Dry Run

Let's trace running the script on a Windows 10 PC named DESKTOP-12345.

1

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

2

Select properties

Select-Object picks CsName, OsName, OsVersion, CsProcessors, CsTotalPhysicalMemory from the full info

3

Format output

Format-List displays the selected properties in a readable list format

StepActionValue
1Get-ComputerInfoCsName=DESKTOP-12345, OsName=Microsoft Windows 10 Pro, OsVersion=10.0.19044, CsProcessors=Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz, Memory=17179869184
2Select-ObjectCsName, OsName, OsVersion, CsProcessors, CsTotalPhysicalMemory
3Format-ListFormatted 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

Using WMI objects
powershell
Get-WmiObject -Class Win32_OperatingSystem | Select-Object CSName, Caption, Version, BuildNumber
This method uses older WMI cmdlets but provides OS details; less comprehensive than Get-ComputerInfo.
Exporting report to a text file
powershell
Get-ComputerInfo | Select CsName, OsName, OsVersion, CsProcessors, CsTotalPhysicalMemory | Format-List | Out-File system_report.txt
Saves the report to a file for sharing or later review.
Using CIM cmdlets
powershell
Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object Name, Manufacturer, Model, TotalPhysicalMemory
CIM cmdlets are newer and faster than WMI, good for hardware info.

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.

ApproachTimeSpaceBest For
Get-ComputerInfoO(1)O(1)Full system info, easy to use
Get-WmiObjectO(1)O(1)Legacy systems, OS details
Get-CimInstanceO(1)O(1)Hardware info, modern cmdlets
💡
Use Format-List to make system info output easier to read in PowerShell.
⚠️
Beginners often forget to select specific properties, resulting in overwhelming output.