Files
Sandbox/Windows-PageFile.ps1
T
Zack Meier 03dba08135 sync
2026-04-15 15:42:41 -05:00

32 lines
2.8 KiB
PowerShell

$AllVMs = Get-VM
$WinVMs = $AllVMs | where-object { $_.Name -like "*.nd.gov" -and $_.Name -notlike "des*" -and $_.Name -notlike "bnd*" -and $_.GuestId -like "Windows*" -and $_.GuestId -notlike "Windows7*" -and $_.ExtensionData.summary.config.ManagedBy.Type -ne "placeholderVm" } | sort-object Name
$WinVMs | Set-Content C:\users\zmeier\desktop\WinVMs.txt
$func = {
$CimInstanceCS = Get-WMIObject -Class Win32_ComputerSystem
$CimInstanceOS = Get-WMIObject -Class Win32_OperatingSystem
$CimInstancePFu = Get-WMIObject -Class Win32_PageFileUsage
$CimInstancePFs = Get-WMIObject -Class Win32_PageFileSetting
$CimInstanceVol = Get-WMIObject -Class Win32_Volume
$obj = [PSCustomObject]@{
ComputerName = $env:COMPUTERNAME
HardwareMemoryGB = [math]::round(($CimInstanceOS.TotalVisibleMemorySize / 1MB), 2);
PageFileAllocatedBaseSizeGB = [math]::round(($CimInstancePFu.AllocatedBaseSize / 1KB), 2);
CommittedMemoryGB = [math]::round(($CimInstanceOS.TotalVirtualMemorySize - $CimInstanceOS.FreeVirtualMemorySize) / 1MB, 2);
CurrentCommittedMemoryGB = [math]::round((Get-Counter -Counter '\memory\% committed bytes in use').CounterSamples.CookedValue / 1GB, 2)
PageFileSystemManaged = If ( $CimInstancePFs.InitialSize -eq 0) { "True" }Else { "False" }
PageFileInitialSizeGB = [math]::round($CimInstancePFs.InitialSize / 1KB, 2);
PageFileMaximumSizeGB = [math]::round($CimInstancePFs.MaximumSize / 1KB, 2);
PageFileCurrentUsageGB = [math]::round(($CimInstancePFu.CurrentUsage / 1KB), 2);
PageFilePeakUsageGB = [math]::round(($CimInstancePFu.PeakUsage / 1KB), 2);
PageFileLocation = $CimInstancePFu.Name;
PageDiskUsageGB = [math]::round((($CimInstanceVol | Where-Object { $_.DriveLetter -eq $CimInstancePFu.Name.split('\')[0] }).Capacity - ($CimInstanceVol | Where-Object { $_.DriveLetter -eq $CimInstancePFu.Name.split('\')[0] }).FreeSpace)/1GB, 2)
PageDiskSizeGB = [math]::round(($CimInstanceVol | Where-Object { $_.DriveLetter -eq $CimInstancePFu.Name.split('\')[0] }).Capacity / 1GB, 2);
PageDiskSizeCorrect = If ([math]::round(($CimInstanceVol | Where-Object { $_.DriveLetter -eq $CimInstancePFu.Name.split('\')[0] }).Capacity / 1GB, 2) -lt [math]::round(($CimInstanceOS.TotalVisibleMemorySize / 1MB), 2)) { $true } Else { $false };
PageFileMaxCorrect = If ([math]::round($CimInstancePFs.MaximumSize / 1KB, 2) -ne 0 -and [math]::round($CimInstancePFs.MaximumSize / 1KB, 2) -lt ([math]::round(($CimInstanceVol | Where-Object { $_.DriveLetter -eq $CimInstancePFu.Name.split('\')[0] }).Capacity / 1GB, 2) - 0.5)) { $true }Else { $false };
}
$obj
}
Invoke-Command -ComputerName $WinVMs -ScriptBlock $func -Credential $AdminCred -ov x