Windows底下用PowerShell写的获取CPU核数、占用率;内存可用内存大小(GB)、使用率;硬盘总空余大小(GB),使用率
# 获取硬盘空余空间
function get_disk_free(){
$disk = Get-WmiObject -Class win32_logicaldisk
$freedisk = $disk.FreeSpace
$freedisk =(($freedisk | Measure-Object -Sum).sum /1gb)
return @($freedisk)
}
echo "{'get_disk_free':'$(get_disk_free)'}"
# 获取磁盘使用率
function get_disk_used_percent(){
$disk = Get-WmiObject -Class win32_logicaldisk
$allSpace = $disk.Size
$allSpace =(($allSpace | Measure-Object -Sum).sum /1gb)
$FreeSpace = $disk.FreeSpace
$FreeSpace =(($FreeSpace | Measure-Object -Sum).sum /1gb)
$disk_used_percent = (($FreeSpace/$allSpace)*100)
return @($disk_used_percent)
}
echo "{'get_disk_used_percent':'$(get_disk_used_percent)'}"
function get_memory_count(){
"{0:N2}GB" -f (((Get-WmiObject -Class Win32_PhysicalMemory).capa