PSSysinfo.psm1
|
function PSSysinfo { param( [String] $output ) $hostname = hostname $winvername = (Get-WmiObject Win32_OperatingSystem).Caption $winvernum = (Get-WmiObject Win32_OperatingSystem).Version $psver = $PSVersionTable.PSVersion.Major if ($PSVersionTable.PSVersion.Major -ge 3) { #Write-Output "PowerShell version: $psver" $cpuinfo = Get-WmiObject win32_processor | Select-Object Name,NumberOfLogicalProcessors,MaxClockSpeed $cpunameprior = @($cpuinfo.Name) $cpucore = ($cpuinfo | Measure-Object -Property NumberOfLogicalProcessors -Sum).sum $cpuclock = @($cpuinfo.MaxClockSpeed)[0] $cpuperc = Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average $load = $cpuperc.Average $boot = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime $os = Get-Ciminstance Win32_OperatingSystem } else { #Write-Output "PowerShell version: $psver" $cpunameprior = @(Get-WmiObject win32_processor | Select-Object -ExpandProperty Name) $cpucore = (@(Get-WmiObject win32_processor | Select-Object -ExpandProperty NumberOfLogicalProcessors) | Measure-Object -Sum).sum $cpuclock = @(Get-WmiObject win32_processor | Select-Object -ExpandProperty MaxClockSpeed)[0] $load = Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select-Object -ExpandProperty Average $boot = (Get-WmiObject Win32_OperatingSystem).ConvertToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime) $os = Get-WmiObject Win32_OperatingSystem } $cpuname = $cpunameprior[0].Trim() $cpuname = $cpuname.Replace('(tm)', '') $cpu = "$cpucore x $cpuname ($cpuclock`MHz, $load`%)" $date = get-date $up = New-TimeSpan -Start $boot -End $date | Select-Object Days,Hours,Minutes $updays = $up.Days $uphours = $up.Hours $upmins = $up.Minutes $uptime = "$updays`d $uphours`h $upmins`m" $RAMTotal = [Math]::Round($os.TotalVisibleMemorySize / 1024 / 1024,2) $RAMFree = [Math]::Round($os.FreePhysicalMemory / 1024 / 1024,2) $RAMUsed = [Math]::Round($RAMTotal - $RAMFree,2) $RAMpctFree = [math]::Round(($os.FreePhysicalMemory/$os.TotalVisibleMemorySize)*100,2) $objDisks = Get-WmiObject -Class win32_logicaldisk -Filter "DriveType = '3'" $DiskResults = @() ForEach( $disk in $objDisks ) { $ThisVolume = "" | select Volume,Capacity,FreeSpace,PercentFree $ThisVolume.Volume = $disk.DeviceID $ThisVolume.Capacity = $([Math]::Round($disk.Size / 1TB,2)) $ThisVolume.FreeSpace = $([Math]::Round($disk.FreeSpace / 1TB,2)) $ThisVolume.PercentFree = $ThisVolume.FreeSpace/$ThisVolume.Capacity*100 $DiskResults += $ThisVolume } IF(($DiskResults | Measure-Object -Property Capacity -Sum).sum -le "0.999") { $DiskResults = @() ForEach( $disk in $objDisks ) { $ThisVolume = "" | select Volume,Capacity,FreeSpace,PercentFree $ThisVolume.Volume = $disk.DeviceID $ThisVolume.Capacity = $([Math]::Round($disk.Size / 1GB,2)) $ThisVolume.FreeSpace = $([Math]::Round($disk.FreeSpace / 1GB,2)) $ThisVolume.PercentFree = $ThisVolume.FreeSpace/$ThisVolume.Capacity*100 $DiskResults += $ThisVolume } $HDDUnits = "GB" } else { $HDDUnits = "TB" } $TotalHDDCapacity = ($DiskResults | Measure-Object -Property Capacity -Sum).sum $TotalHDDFreeSpace = ($DiskResults | Measure-Object -Property FreeSpace -Sum).sum $TotalHDDUsedSpace = [Math]::Round($TotalHDDCapacity - $TotalHDDFreeSpace,2) $TotalHDDPercFree = [Math]::Round($TotalHDDFreeSpace / $TotalHDDCapacity * 100,2) $TotalHDDPercUsed = [Math]::Round($TotalHDDUsedSpace / $TotalHDDCapacity * 100,2) if($output -eq "mirc") { " 12Hostname: 04$hostname 12OS: 04$winvername ($winvernum) 12CPU: 04$cpu 12Uptime: 04$uptime 12Memory Usage: 04$RAMUsed`GB/$RAMTotal`GB ($RAMpctFree% free) 12Disk Usage: 04$TotalHDDUsedSpace`TB/$TotalHDDCapacity`TB ($TotalHDDPercUsed%) " | clip } elseif ($output -eq "weechat") { Write-Host "Not implemented yet." } else { Write-Host "Hostname: $hostname OS: $winvername ($winvernum) CPU: $cpu Uptime: $uptime Memory Usage: $RAMUsed`GB/$RAMTotal`GB ($RAMpctFree% free) Disk Usage: $TotalHDDUsedSpace$HDDUnits/$TotalHDDCapacity$HDDUnits ($TotalHDDPercUsed%)" } #"`\cC12`Hostname: `\cC04`$hostname OS: $winvername ($winvernum) CPU: $cpu Uptime: $uptime Memory Usage: $RAMUsed`GB/$RAMTotal`GB ($RAMpctFree% free) Disk Usage: $TotalHDDUsedSpace$HDDUnits/$TotalHDDCapacity$HDDUnits ($TotalHDDPercUsed%)" | clip } |