日期:2014-05-17 浏览次数:20644 次
$Server = "192.168.0.62"
$cpu = gwmi –computername $Server win32_Processor
$men = gwmi -ComputerName $Server win32_OperatingSystem
$Disks = gwmi –computername $Server win32_logicaldisk -filter "drivetype=3"
$Havecpu = "{0:0.0} %" -f $cpu.LoadPercentage
$CpuType =$cpu.name
$CpuSpeed = $cpu.maxclockspeed /1000
$Allmen = "{0:0.0} MB" -f ($men.TotalVisibleMemorySize / 1KB)
$Freemen = "{0:0.0} MB" -f ($men.FreePhysicalMemory / 1KB)
$Permem = "{0:0.0} %" -f ((($men.TotalVisibleMemorySize-$men.FreePhysicalMemory)/$men.TotalVisibleMemorySize)*100)
Write-Host "====================================================================================="
$message = "====================================================================================="
Write-Host "服务器$Server 当前系统状态信息如下:" -ForegroundColor Blue
$message = "$message`n服务器$Server 当前系统状态信息如下:"
Write-Host "====================================================================================="
$message = "$message`n====================================================================================="
Write-Host "CPU型号: $CpuType" -ForegroundColor Green
Write-Host "CPU主频: $CpuSpeed G" -ForegroundColor Green
Write-Host "CPU利用率: $Havecpu" -ForegroundColor Green
Write-Host "内存总数: $Allmen" -ForegroundColor Green
Write-Host "内存可用数: $Freemen" -ForegroundColor Green
Write-Host "内存使用率: $Permem" `n -ForegroundColor Green
$Info=@{
"CPU 型号 " ="$CpuType" ;
"CPU 主频 " =" $CpuSpeed G" ;
"CPU 利用率" =" $Havecpu" ;
"内存 总数" = " $Allmen";
"内存可用数" = $Freemen;
"内存使用率" = $Permem}
$Info2 = $Info |Format-Table |out-string
$message = "$message`n$Info2"
$message2=Get-WmiObject win32_logicaldisk -computername `
$Server|Where-Object{$_.DriveType -eq 3} |Format-Table `
-auto systemname,DeviceID,`
@{label="FreeSpace (GB)";expression={"{0:F2}" -f ($_.FreeSpace/1024/1024/1024)}},`
@{label="TotalSize (GB)";expression={"{0:F2}" -f ($_.Size/1024/1024/1024)}},`
@{label="Note";
expression={
if(($_.FreeSpace/1024/1024/1024) -lt 5)
{"此硬盘剩余空间小于5G,请及时释放!!"}
else{}
}
} |out-string
Write-Host "磁盘空间预警 $message2" -ForegroundColor Green
$message = "$message`n`n磁盘空间预警 $message2"
Write-Host "====================================================================================="
$message = "$message`n====================================================================================="
#获取当前正在运行的服务名称
Write-Host "服务器$Server 当前正在运行的进程如下:" -ForegroundColor Blue
$message = "$message`n服务器$Server 当前正在运行的进程如下:"
Write-Host "=======================================================