System Information Gatherer

Description:

This PowerShell script is designed for beginners to learn how to gather and display basic system information. It demonstrates how to use various PowerShell cmdlets to retrieve information about the computer’s hardware, operating system, and current user. The script also introduces basic formatting techniques to present the information in a readable manner.

Full Script:

# System Information Gatherer

# Function to get and display system information
function Get-SystemInfo {
    Clear-Host
    Write-Host "=== System Information Gatherer ===" -ForegroundColor Cyan

    # Get computer system information
    $computerSystem = Get-CimInstance CIM_ComputerSystem
    $operatingSystem = Get-CimInstance CIM_OperatingSystem

    # Display basic system information
    Write-Host "`nComputer Name: " -NoNewline -ForegroundColor Yellow
    Write-Host $computerSystem.Name

    Write-Host "Manufacturer: " -NoNewline -ForegroundColor Yellow
    Write-Host $computerSystem.Manufacturer

    Write-Host "Model: " -NoNewline -ForegroundColor Yellow
    Write-Host $computerSystem.Model

    Write-Host "Operating System: " -NoNewline -ForegroundColor Yellow
    Write-Host $operatingSystem.Caption

    Write-Host "OS Version: " -NoNewline -ForegroundColor Yellow
    Write-Host $operatingSystem.Version

    # Get and display CPU information
    $processor = Get-CimInstance CIM_Processor
    Write-Host "`nCPU Information:" -ForegroundColor Green
    Write-Host "Name: $($processor.Name)"
    Write-Host "Cores: $($processor.NumberOfCores)"
    Write-Host "Logical Processors: $($processor.NumberOfLogicalProcessors)"

    # Get and display memory information
    $totalMemory = [math]::Round($computerSystem.TotalPhysicalMemory / 1GB, 2)
    Write-Host "`nMemory Information:" -ForegroundColor Green
    Write-Host "Total Physical Memory: $totalMemory GB"

    # Get and display disk information
    Write-Host "`nDisk Information:" -ForegroundColor Green
    Get-CimInstance CIM_LogicalDisk | Where-Object {$_.DriveType -eq 3} | ForEach-Object {
        $freeSpace = [math]::Round($_.FreeSpace / 1GB, 2)
        $totalSize = [math]::Round($_.Size / 1GB, 2)
        Write-Host "Drive $($_.DeviceID): $freeSpace GB free of $totalSize GB"
    }

    # Get and display current user information
    $currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent()
    Write-Host "`nCurrent User Information:" -ForegroundColor Green
    Write-Host "Username: $($currentUser.Name)"
}

# Main program
Get-SystemInfo

# Pause to keep the console window open
Read-Host "`nPress Enter to exit..."

This script includes:

  1. A function Get-SystemInfo that gathers and displays various system information
  2. Use of PowerShell cmdlets like Get-CimInstance to retrieve system data
  3. Formatting techniques to make the output more readable (colors, alignment)
  4. Basic math operations to convert bytes to gigabytes
  5. Use of pipeline and Where-Object for filtering disk information
  6. Retrieval of current user information

The script provides a comprehensive overview of the system’s hardware and software configuration, making it useful for beginners to understand how to access and present system information using PowerShell. It also introduces concepts like working with CIM instances, formatting output, and basic data manipulation.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *