PS脚本如下:
1 $Server = $env:computername 2 #server's CPU Mem Hardinfor 3 $cpu = gwmi –computername $Server win32_Processor 4 $men = gwmi -ComputerName $Server win32_OperatingSystem 5 $Disks = gwmi –Computer: $Server win32_logicaldisk -filter "drivetype=3" 6 $Havecpu = "{0:0.0} %" -f $cpu.LoadPercentage 7 $Allmen = "{0:0.0} MB" -f ($men.TotalVisibleMemorySize / 1KB) 8 $Freemen = "{0:0.0} MB" -f ($men.FreePhysicalMemory / 1KB) 9 $Permem = "{0:0.0} %" -f ((($men.TotalVisibleMemorySize-$men.FreePhysicalMemory)/$men.TotalVisibleMemorySize)*100) 10 Write-Host "COMPUTER:$Server"`r`n 11 Write-Host "CPU: $Havecpu"`r`n 12 Write-Host "Total Mem:$Allmen"`r`n 13 Write-Host "Left Mem:$Freemen"`r`n 14 Write-Host "Used Mem:$Permem"`r`n 15 $IpAdd = (Get-WmiObject -class win32_NetworkAdapterConfiguration -Filter 'ipenabled = "true"').ipaddress[0] 16 Write-Host "Ipaddress:$IpAdd"`r`n
将之封闭为BAT运行,并将结果COPY至统一机器共享内:
powershell .\GetCPUMem.ps1 > \\XXX\Iperf\log\%computername%.txt
下一步,必然是通过BAT或PS在每个客户机上建立相应的SCHEDULE TASK啦。
然后,集中数据,一方面将数据导入SQL用于以后分析,通过WEB即时访问,固定时间通过邮件发送REPORT。
相应的TXT文件内容亦如是:
COMPUTER:KOALA
CPU: 2.0 %
Total Mem:3992.9 MB
Left Mem:1279.6 MB
Used Mem:68.0 %
Ipaddress:X.X.X.X