Resources now calculates RAM usage correctly when more than one RAM stick is installed

This commit is contained in:
Zachary Gorman 2024-08-13 08:24:56 -07:00
parent c7ddd76b5a
commit 346c7ef571
2 changed files with 23 additions and 14 deletions

View file

@ -11,11 +11,23 @@ function get-resources {
$sysProc = Get-WmiObject -Class Win32_Processor $sysProc = Get-WmiObject -Class Win32_Processor
$sysMem = Get-WmiObject -Class Win32_PhysicalMemory $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 # Get processor usage
$procUsage = [math]::Round((Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples.CookedValue) $procUsage = [math]::Round((Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples.CookedValue)
# Get memory usage # 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 # Get Physical Network Adapter information
$netAdapters = Get-NetAdapter -physical | Where-Object status -eq 'up' $netAdapters = Get-NetAdapter -physical | Where-Object status -eq 'up'
@ -25,9 +37,9 @@ function get-resources {
$freeDisk = $compFreeSpace[0] $freeDisk = $compFreeSpace[0]
$maxDisk = $compfreeSpace[1] $maxDisk = $compfreeSpace[1]
$obj | Add-Member -MemberType NoteProperty -Name 'OS' -Value $($sysInfo.Caption) $obj | Add-Member -MemberType NoteProperty -Name 'OS' -Value $sysOS
$obj | Add-Member -MemberType NoteProperty -Name 'Version' -Value $($sysInfo.Version) $obj | Add-Member -MemberType NoteProperty -Name 'Version' -Value $sysVersion
$obj | Add-Member -MemberType NoteProperty -Name 'TotalMem' -Value $($sysMem.Capacity/1GB) $obj | Add-Member -MemberType NoteProperty -Name 'TotalMem' -Value $sysTotalMem
$obj | Add-Member -MemberType NoteProperty -Name 'MemUsage' -Value $memUsage $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 'Processor' -Value $($sysProc.Name)
$obj | Add-Member -MemberType NoteProperty -Name 'NumberOfCores' -Value $($sysProc.NumberOfCores) $obj | Add-Member -MemberType NoteProperty -Name 'NumberOfCores' -Value $($sysProc.NumberOfCores)
@ -56,11 +68,9 @@ function get-resources {
$speed = $netAdapter.Speed $speed = $netAdapter.Speed
if ($speed -gt 1000000000) { if ($speed -gt 1000000000) {
$speed = "{0} Gbps" -f ($speed/1000000000) $speed = "{0} Gbps" -f ($speed/1000000000)
} else { } elseif($speed -gt 1000000){
if($speed -gt 1000000){ $speed = "{0} Mbps" -f ($speed/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"
} }
} }

View file

@ -90,7 +90,6 @@ Function Get-PC {
[Switch]$Bypass, [Switch]$Bypass,
[Switch]$ClearCCMCache, [Switch]$ClearCCMCache,
[switch]$Devices, [switch]$Devices,
[switch]$EnableSpark,
[Switch]$EventLog, [Switch]$EventLog,
[switch]$Excel, [switch]$Excel,
[Switch]$FileSystem, [Switch]$FileSystem,
@ -465,11 +464,11 @@ Function Get-PC {
if ($compStatus -ne 'Online') { if ($compStatus -ne 'Online') {
Write-Warning "$comp is $compStatus unable to proccess command" Write-Warning "$comp is $compStatus unable to proccess command"
break continue
} }
Get-GPUpdate $comp Get-GPUpdate $comp
break continue
} }
#Will not notify the user that another user is about to remote onto their PC #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') { if ($compStatus -ne 'Online') {
Write-Warning "$comp is $compStatus unable to proccess command" Write-Warning "$comp is $compStatus unable to proccess command"
break continue
} }
Invoke-ClearCCMCache $comp Invoke-ClearCCMCache $comp
break continue
} }
#Will log off the current logged in user for the designated PC #Will log off the current logged in user for the designated PC