Automated System Information Gatherer Script
This PowerShell script automates the process of gathering system information, including OS details, hardware specifications, and running services. By providing a comprehensive overview, this script is invaluable for system audits, troubleshooting, and inventory management.
Step 1: Gather Operating System Information
First, we will retrieve information about the system’s operating system, including the name, version, and build number.
$osInfo = Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object Name, Version, BuildNumber, OSArchitecture, LastBootUpTime $osInfo
In this step, we use the `Get-CimInstance` cmdlet to access the `Win32_OperatingSystem` class, which contains essential data about the operating system. The `Select-Object` cmdlet ensures that we only display relevant fields.
Step 2: Retrieve Hardware Information
Next, we will gather details about the system’s processor and memory capacity.
$cpuInfo = Get-CimInstance -ClassName Win32_Processor | Select-Object Name, NumberOfCores, NumberOfLogicalProcessors, MaxClockSpeed $memoryInfo = Get-CimInstance -ClassName Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum $totalMemoryGB = [math]::round($memoryInfo.Sum / 1GB, 2) $cpuInfo $totalMemoryGB
This block retrieves the CPU details (name, core count, logical processors, and max speed) and calculates the total physical memory by summing the capacities of each memory stick. The result is converted to gigabytes for easier understanding.
Step 3: List Installed Software
We will compile a list of installed software by checking the `Win32_Product` class, which provides information about the products installed on the system.
$installedSoftware = Get-CimInstance -ClassName Win32_Product | Select-Object Name, Version, Vendor $installedSoftware
Using the `Get-CimInstance` cmdlet once more, we access the `Win32_Product` class to enumerate the installed software. The output includes the name, version, and vendor of each application.
Step 4: Check Running Services
Next, we will retrieve information about the currently running services, focusing on their statuses and display names.
$runningServices = Get-Service | Where-Object { $_.Status -eq 'Running' } | Select-Object DisplayName, ServiceName, Status $runningServices
In this step, we utilize the `Get-Service` cmdlet to list all services, filtering to show only those that are currently running. The output will display the service’s display name, service name, and status.
Step 5: Output Summary Report
Finally, we will format a summary report combining all collected information to display it in a user-friendly format.
Write-Host "System Information Summary Report" Write-Host "-------------------------------------" Write-Host "Operating System: $($osInfo.Name), Version: $($osInfo.Version), Build: $($osInfo.BuildNumber), Architecture: $($osInfo.OSArchitecture)" Write-Host "Last Boot Time: $($osInfo.LastBootUpTime)" Write-Host "CPU Info: $($cpuInfo.Name), Cores: $($cpuInfo.NumberOfCores), Logical Processors: $($cpuInfo.NumberOfLogicalProcessors), Max Clock Speed: $($cpuInfo.MaxClockSpeed) MHz" Write-Host "Total Physical Memory: $totalMemoryGB GB" Write-Host "-------------------------------------" Write-Host "Running Services:" $runningServices | Format-Table -AutoSize Write-Host "-------------------------------------" Write-Host "Installed Software:" $installedSoftware | Format-Table -AutoSize
This final block organizes and prints a summary report of the system’s information, including OS, CPU, total memory, running services, and installed software. This makes it easy for system administrators to assess the machine’s health and inventory.
By using this automated script, administrators can efficiently gather comprehensive system information, making it easier to perform audits, troubleshoot issues, and manage software inventories. This tool enhances day-to-day operations and contributes to better system management practices.