From 346c7ef5712f14a843f36fc243312d0ad6349be9 Mon Sep 17 00:00:00 2001 From: Zachary Gorman Date: Tue, 13 Aug 2024 08:24:56 -0700 Subject: [PATCH] Resources now calculates RAM usage correctly when more than one RAM stick is installed --- Private/Resources.ps1 | 28 +++++++++++++++++++--------- Public/Get-PC.ps1 | 9 ++++----- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Private/Resources.ps1 b/Private/Resources.ps1 index b90f3c8..cc7ecec 100644 --- a/Private/Resources.ps1 +++ b/Private/Resources.ps1 @@ -11,11 +11,23 @@ function get-resources { $sysProc = Get-WmiObject -Class Win32_Processor $sysMem = Get-WmiObject -Class Win32_PhysicalMemory + $sysOS = $sysInfo.Caption + $sysVersion = $sysInfo.Version + if ($sysMem.Length) { + $sysTotalMem = 0 + foreach ($mem in $sysMem) { + $sysTotalMem += $mem.Capacity + } + $sysTotalMem /= 1GB + } else { + $sysTotalMem = $sysMem.Capacity / 1GB + } + # Get processor usage $procUsage = [math]::Round((Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples.CookedValue) # Get memory usage - $memUsage = [Math]::Round((1 - (Get-Counter '\Memory\Available MBytes').CounterSamples.CookedValue/($sysMem.Capacity/1MB))*100,1) + $memUsage = [Math]::Round((1 - (Get-Counter '\Memory\Available MBytes').CounterSamples.CookedValue/($sysTotalMem*1GB/1MB))*100,1) # Get Physical Network Adapter information $netAdapters = Get-NetAdapter -physical | Where-Object status -eq 'up' @@ -25,9 +37,9 @@ function get-resources { $freeDisk = $compFreeSpace[0] $maxDisk = $compfreeSpace[1] - $obj | Add-Member -MemberType NoteProperty -Name 'OS' -Value $($sysInfo.Caption) - $obj | Add-Member -MemberType NoteProperty -Name 'Version' -Value $($sysInfo.Version) - $obj | Add-Member -MemberType NoteProperty -Name 'TotalMem' -Value $($sysMem.Capacity/1GB) + $obj | Add-Member -MemberType NoteProperty -Name 'OS' -Value $sysOS + $obj | Add-Member -MemberType NoteProperty -Name 'Version' -Value $sysVersion + $obj | Add-Member -MemberType NoteProperty -Name 'TotalMem' -Value $sysTotalMem $obj | Add-Member -MemberType NoteProperty -Name 'MemUsage' -Value $memUsage $obj | Add-Member -MemberType NoteProperty -Name 'Processor' -Value $($sysProc.Name) $obj | Add-Member -MemberType NoteProperty -Name 'NumberOfCores' -Value $($sysProc.NumberOfCores) @@ -56,11 +68,9 @@ function get-resources { $speed = $netAdapter.Speed if ($speed -gt 1000000000) { $speed = "{0} Gbps" -f ($speed/1000000000) - } else { - if($speed -gt 1000000){ - $speed = "{0} Mbps" -f ($speed/1000000) - } + } elseif($speed -gt 1000000){ + $speed = "{0} Mbps" -f ($speed/1000000) } - Write-Host "Name: $($netAdapter.InterfaceDescription) Type: $($netAdapter.name), Link Speed: $speed" + Write-Host "$($netAdapter.InterfaceDescription)`r`n`tType: $($netAdapter.name)`r`n`tLink Speed: $speed" } } \ No newline at end of file diff --git a/Public/Get-PC.ps1 b/Public/Get-PC.ps1 index e69379f..a2d1290 100644 --- a/Public/Get-PC.ps1 +++ b/Public/Get-PC.ps1 @@ -90,7 +90,6 @@ Function Get-PC { [Switch]$Bypass, [Switch]$ClearCCMCache, [switch]$Devices, - [switch]$EnableSpark, [Switch]$EventLog, [switch]$Excel, [Switch]$FileSystem, @@ -465,11 +464,11 @@ Function Get-PC { if ($compStatus -ne 'Online') { Write-Warning "$comp is $compStatus unable to proccess command" - break + continue } Get-GPUpdate $comp - break + continue } #Will not notify the user that another user is about to remote onto their PC @@ -534,10 +533,10 @@ Function Get-PC { if ($compStatus -ne 'Online') { Write-Warning "$comp is $compStatus unable to proccess command" - break + continue } Invoke-ClearCCMCache $comp - break + continue } #Will log off the current logged in user for the designated PC