메모리 VM 얻기 - Powershell
10408 단어 powershellscriptvmmemory
[CmdletBinding()]
param(
[Parameter(ValueFromPipelineByPropertyName=$true)][alias("DNSHostName","Name")]$ComputerName = '.',
[PSCredential]$Credential
)
BEGIN {}
PROCESS {
Foreach ($Comp in $ComputerName) {
$param = @{
'ComputerName' = $Comp
'ErrorVariable' = 'WmiRequestError'
}
if($Credential -and ($Comp -notin @($env:COMPUTERNAME,'.'))){$param.Credential = $Credential}
try{
$PerfOS_Memory = Get-WmiObject -Class Win32_PerfRawData_PerfOS_Memory @param
$PhysicalMemory = Get-WmiObject -Class Win32_PhysicalMemory @param
$TotalPhysicalMemory = ($PhysicalMemory | Measure-Object -Sum -Property Capacity).Sum
} Catch {$WmiRequestError; break}
if($PerfOS_Memory -and !$WmiRequestError){
[pscustomobject][ordered]@{
'ComputerName' = $PerfOS_Memory.PSComputerName
'AvailableGB' = [System.Math]::Round(($PerfOS_Memory.AvailableBytes/1gb),2)
'inUseGB' = [System.Math]::Round(($TotalPhysicalMemory/1gb - $PerfOS_Memory.AvailableBytes/1gb),2)
'CacheGB' = [System.Math]::Round(($PerfOS_Memory.CacheBytes/1gb),2)
'CommittedGB' = [System.Math]::Round(($PerfOS_Memory.CommittedBytes/1gb),2)
'CommitLimitGB' = [System.Math]::Round(($PerfOS_Memory.CommitLimit/1gb),2)
'PoolPagedMB' = [System.Math]::Round(($PerfOS_Memory.PoolPagedBytes/1mb),2)
'PoolNonpagedMB' = [System.Math]::Round(($PerfOS_Memory.PoolNonpagedBytes/1mb),2)
'TotalPhysicalMemory' = [System.Math]::Round(($TotalPhysicalMemory/1gb),2)
'ModuleSize' = ($PhysicalMemory | Group-Object -Property Capacity | % {[string]$($_.Count.ToString() + ' x ' + ($_.Name / 1GB).ToString() + 'GB')}) -join ', '
}
}
$PerfOS_Memory = $Null
$PhysicalMemory = $Null
$TotalPhysicalMemory = $Null
$WmiRequestError = $Null
}
}
END {}
Reference
이 문제에 관하여(메모리 VM 얻기 - Powershell), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/redhcp/obtain-memory-vm-powershell-4lba텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)