Get-WindowsMemory.ps1
<#PSScriptInfo .VERSION 1.0 .GUID aea43ca3-73aa-4262-9f20-5e73c134af11 .AUTHOR saw-friendship .COMPANYNAME .COPYRIGHT saw-friendship .TAGS Windows WMI Remote Memory Sytem .LICENSEURI .PROJECTURI .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION Get Windows UpTime StartTime and LocalTime by Wmi on local and remote system .LINK https://sawfriendship.wordpress.com/ .EXAMPLE Get-WindowsMemory .EXAMPLE Get-WindowsMemory FileServer01 -Credential (Get-Credential) .EXAMPLE Get-WindowsMemory FileServer01,FileServer02 #> [CmdletBinding()] param( [Parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)][Alias("Host","DNSHostName","IP","IPAddress")][string[]]$ComputerName = $env:COMPUTERNAME, [PSCredential]$Credential ) $ComputerCount = $ComputerName.count [int]$i = 0 $ComputerName | % { if($ComputerCount -gt 1){Write-Progress -Activity $_ -PercentComplete ($i / $ComputerCount * 100)} $i += 1 if($_ -eq $env:COMPUTERNAME){ try{ $PerfOS_Memory = Get-WmiObject -Class Win32_PerfRawData_PerfOS_Memory -ComputerName $_ -ErrorVariable WmiRequestError $PhysicalMemory = Get-WmiObject -Class Win32_PhysicalMemory -ComputerName $_ -ErrorVariable WmiRequestError $TotalPhysicalMemory = ($PhysicalMemory | Measure-Object -Sum -Property Capacity).Sum } Catch {$WmiRequestError; break} } else { try{ $PerfOS_Memory = Get-WmiObject -Class Win32_PerfRawData_PerfOS_Memory -ComputerName $_ -Credential $Credential -ErrorVariable WmiRequestError $PhysicalMemory = Get-WmiObject -Class Win32_PhysicalMemory -ComputerName $_ -Credential $Credential -ErrorVariable WmiRequestError $TotalPhysicalMemory = ($PhysicalMemory | Measure-Object -Sum -Property Capacity).Sum } Catch {$WmiRequestError; break} } if($PerfOS_Memory -and !$WmiRequestError){ [pscustomobject][ordered]@{ 'ComputerName' = $PerfOS_Memory.PSComputerName 'AvailableGB' = $PerfOS_Memory.AvailableBytes/1gb 'inUseGB' = $TotalPhysicalMemory/1gb - $PerfOS_Memory.AvailableBytes/1gb 'CacheGB' = $PerfOS_Memory.CacheBytes/1gb 'CommittedGB' = $PerfOS_Memory.CommittedBytes/1gb 'CommitLimitGB' = $PerfOS_Memory.CommitLimit/1gb 'PoolPagedMB' = $PerfOS_Memory.PoolPagedBytes/1mb 'PoolNonpagedMB' = $PerfOS_Memory.PoolNonpagedBytes/1mb 'TotalPhysicalMemory' = $TotalPhysicalMemory/1gb } } $PerfOS_Memory = $Null $PhysicalMemory = $Null $TotalPhysicalMemory = $Null $WmiRequestError = $Null } |