Functions/Get-SystemInfo.ps1
function Get-SystemInfo { [CmdletBinding()] param ( ) # BatteryStatus # EstimatedChargeRemaining : 100 # EstimatedRunTime : 71582788 # $NetAdapters = Get-NetAdapter | Where-Object { $_.HardwareInterface -eq $true -and $_.Status -eq "Up" } # $NetAdapters $counters = @( "\Processor(*)\% Processor Time" "\Memory\Available Bytes" "\PhysicalDisk(**)\% Idle Time" "\PhysicalDisk(**)\Avg. Disk sec/Read" "\PhysicalDisk(**)\Avg. Disk sec/Write" "\PhysicalDisk(**)\Current Disk Queue Length" "\Paging File(**)\% Usage" "\Network Interface(*)\Bytes Total/sec" "\Network Interface(*)\Bytes Sent/sec" "\Network Interface(*)\Bytes received/sec" # "\Network Interface(*)\Output Queue Length" # "\Processor Information(_total)\% of Maximum Frequency" # "\Processor Information(_total)\Processor frequency" ) # $counters Write-Progress -Activity "Starting jobs..." $jobs = $counters | ForEach-Object { Start-Job -ScriptBlock { ((Get-Counter -Counter $using:_).CounterSamples) } -ArgumentList $_ } # Write-Verbose ($Perf | Select-Object Path, InstanceName, CookedValue | Format-Table -AutoSize | Out-String) -Verbose # $Perf | Where-Object { $_.Path -match "physicaldisk" -and $_.InstanceName -ne "_total" } | Format-Table -AutoSize # $Perf | Where-Object { $_.Path -Match "processor time" -and $_.InstanceName -eq "_total" } | ft -AutoSize $win32_operatingsystem = Get-CimInstance -Class Win32_OperatingSystem $win32_battery = Get-CimInstance win32_battery $uptime = (Get-Uptime).TotalSeconds $ts = [timespan]::fromseconds($uptime) $uptime = ("{0:dd\.hh\:mm\:ss}" -f $ts) $CPUmodel = Get-CimInstance win32_processor | Select-Object -ExpandProperty Name $Win32_ComputerSystemProduct = Get-CimInstance Win32_ComputerSystemProduct $reg_windowsversion = Get-ItemProperty "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion" Write-Progress -Activity "Waiting for jobs to finish..." $Perf = $jobs | Wait-Job | Receive-Job $jobs | Remove-Job $CPUPercentageTotal = [System.Math]::Round($($Perf | Where-Object { $_.Path -Match "processor time" -and $_.InstanceName -eq "_total" } | Select-Object -ExpandProperty CookedValue), 2) # $CPUClockspeed = $($Perf | Where-Object { $_.Path -Match "processor frequency" -and $_.InstanceName -eq "_total" } | Select-Object -ExpandProperty CookedValue) / 1000 $MemoryAvailable = [math]::round($($Perf | Where-Object { $_.Path -Match "Memory\\Available Bytes" } | Select-Object -ExpandProperty CookedValue) / 1024 / 1024 / 1024, 2) $TotalPhysicalRAM = [math]::round(($win32_operatingsystem | Select-Object -ExpandProperty TotalVisibleMemorySize) / 1024 / 1024, 1) $MemoryInUse = ($TotalPhysicalRAM - $MemoryAvailable) $DiskInfo = $Perf | Where-Object { $_.Path -Match "physicaldisk" -and $_.InstanceName -ne "_total" } | Sort-Object InstanceName $NetworkInfo = $Perf | Where-Object { $_.Path -Match "network interface" -and $_.CookedValue -gt 0 } | Sort-Object InstanceName Write-Host "----------" Write-Host "CPU: $($CPUPercentageTotal)%" Write-Host "CPU model: $CPUmodel" Write-Host "Memory: $($MemoryInUse) / $TotalPhysicalRAM GB" # $MemoryAvailable $DiskInfo | ForEach-Object { $counter = ($_.Path -split "\\")[-1] $cookedValue = $([math]::round($_.CookedValue, 2)) if ($_.Path -match "idle time") { $counter = "disk activity" $cookedValue = [math]::round(100 - $cookedValue, 2) $cookedValue = "$($cookedValue)%" } Write-Output "Disk $($_.InstanceName) $counter - $cookedvalue" } $NetworkInfo | ForEach-Object { $counter = ($_.Path -split "\\")[-1] $cookedValue = $([math]::round($_.CookedValue / 1024 , 2)) Write-Output "$($_.InstanceName) M$($counter) - $($cookedvalue)Mbps" } Write-Host "OS: $($win32_operatingsystem.Caption) $($reg_windowsversion.DisplayVersion) ($($win32_operatingsystem.Version).$($reg_windowsversion.UBR))" Write-Host "Computer Name: $($win32_operatingsystem.CSName)" Write-Host "Computer Model: $($Win32_ComputerSystemProduct.Name)" if ($win32_battery) { Write-Host "Battery: $($win32_battery.EstimatedChargeRemaining)%" } Write-Host "Uptime: $uptime" Write-Host "----------" Get-Process | Sort-Object CPU -Descending | Select-Object -First 10 | Format-Table -AutoSize Write-Host "----------" Get-Process | Sort-Object PM -Descending | Select-Object -First 10 | Format-Table -AutoSize } |