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" # SLOW # # "\PhysicalDisk(**)\Avg. Disk sec/Read" # SLOW # # "\PhysicalDisk(**)\Avg. Disk sec/Write" # SLOW # # "\PhysicalDisk(**)\Current Disk Queue Length" # SLOW # # "\Paging File(**)\% Usage" # NOT USED # # "\Network Interface(*)\Bytes Total/sec" # SLOW # # "\Network Interface(*)\Bytes Sent/sec" # SLOW # # "\Network Interface(*)\Bytes received/sec" # SLOW # ) # $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_Processor_job = Start-Job -ScriptBlock { Get-CimInstance Win32_Processor } # $ProcessorTime = (Get-Counter "\Processor(_Total)\% Processor Time").CounterSamples.CookedValue $win32_operatingsystem = Get-CimInstance -Class Win32_OperatingSystem $win32_battery = Get-CimInstance win32_battery $Win32_ComputerSystemProduct = Get-CimInstance Win32_ComputerSystemProduct $Processes = Get-Process -IncludeUserName if (Get-Command Get-Uptime -ea 0) { $uptime = (Get-Uptime).TotalSeconds $uptime_ts = [timespan]::fromseconds($uptime) $uptime = ("{0:dd\.hh\:mm\:ss}" -f $uptime_ts) } $reg_windowsversion = Get-ItemProperty "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion" $win32_Processor = $win32_Processor_job | Wait-Job | Receive-Job $win32_Processor_job | Remove-Job $CPUPercentageTotal = $win32_Processor.LoadPercentage if (!($CPUPercentageTotal)) { $CPUPercentageTotal = "0" } $CPUmodel = $win32_Processor.Name # $CPUClockspeed = $($Perf | Where-Object { $_.Path -Match "processor frequency" -and $_.InstanceName -eq "_total" } | Select-Object -ExpandProperty CookedValue) / 1000 $MemoryAvailable = [math]::round($win32_operatingsystem.FreePhysicalMemory / 1024 / 1024, 1) $TotalPhysicalRAM = [math]::round(($win32_operatingsystem | Select-Object -ExpandProperty TotalVisibleMemorySize) / 1024 / 1024, 1) $MemoryInUse = ($TotalPhysicalRAM - $MemoryAvailable) $volumes = Get-Volume | Where-Object DriveLetter | Sort-Object DriveLetter # $IpInfo = gip -all | ? # $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 # $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" # } $Result = @() # Write-Host "----------" -ForegroundColor Green $Result += [pscustomobject]@{ Name = "CPU" Value = "$($CPUPercentageTotal)% ($($CPUmodel))" } $Result += [pscustomobject]@{ Name = "Memory" Value = "$($MemoryInUse) / $TotalPhysicalRAM GB" } $Result += [pscustomobject]@{ Name = "Processes" Value = ($Processes).Count } foreach ($v in $volumes) { $sizeUsed = $v.Size - $v.SizeRemaining $Result += [pscustomobject]@{ Name = "Volume $($v.DriveLetter) used" Value = "$([math]::Round($sizeUsed / 1GB)) / $([math]::Round($v.Size / 1GB)) GB" } } foreach ($adapter in Get-NetAdapter | Where-Object Status -EQ Up | Sort-Object Name, Type) { foreach ($ipinterface in Get-NetIPAddress -AddressFamily IPv4 | Where-Object InterfaceAlias -EQ $adapter.Name) { $Result += [PSCustomObject]@{ Name = $adapter.name # Type = $ipinterface.AddressFamily Value = $ipinterface.IPAddress } } } $Result += [pscustomobject]@{ Name = "Logged on users:" Value = ($Processes | Where-Object ProcessName -EQ "ShellExperienceHost").Count } $Result += [pscustomobject]@{ Name = "OS" Value = "$($win32_operatingsystem.Caption) $($reg_windowsversion.DisplayVersion) ($($win32_operatingsystem.Version).$($reg_windowsversion.UBR))" } $Result += [pscustomobject]@{ Name = "Computer Name" Value = "$($win32_operatingsystem.CSName)" } $Result += [pscustomobject]@{ Name = "Computer Model" Value = "$($Win32_ComputerSystemProduct.Name)" } if ($win32_battery) { $Result += [pscustomobject]@{ Name = "Battery" Value = "$($win32_battery.EstimatedChargeRemaining)%" } } if ($uptime) { $Result += [pscustomobject]@{ Name = "Uptime" Value = $uptime } } return $Result # Write-Host "----------" -ForegroundColor Green # $Processes = Get-Process # $Processes | Sort-Object CPU -Descending | Select-Object -First 10 | Format-Table -AutoSize # Write-Host "----------" # $Processes | Sort-Object PM -Descending | Select-Object -First 10 | Format-Table -AutoSize } |