Hello all,
I am newbie in powershell scripting and trying to get cpu,memory and diskspace in windows 2k12
I have tried to make but i am getting output in mess manner and wrap text i need output should be in table format.
Please help me to make this.
Thanks.
$ServerListFile = "D:\serverList.txt" $ServerList = Get-Content $ServerListFile -ErrorAction SilentlyContinue $Result = @() ForEach($computername in $ServerList) { $AVGProc = Get-WmiObject -computername $computername win32_processor | Measure-Object -property LoadPercentage -Average | Select Average $OS = gwmi -Class win32_operatingsystem -computername $computername | Select-Object @{Name = "MemoryUsage"; Expression = {“{0:N2}” -f ($_.FreePhysicalMemory / 1000000 ) }} $mem = gwmi -Class win32_operatingsystem -computername $computername | Select-Object @{Name = "Memorypercentage"; Expression = {“{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }} $vol = Get-WmiObject -Class win32_Volume -ComputerName $computername -Filter "DriveLetter = 'C:'" | Select-object @{Name = "C PercentFree"; Expression = {“{0:N2}” -f (($_.FreeSpace/1GB));"GB";"/";(($_.Capacity/1GB));"GB"; } } $dvol = Get-WmiObject -Class win32_Volume -ComputerName $computername -Filter "DriveLetter = 'D:'" | Select-object @{Name = "D PercentFree"; Expression = {“{0:N2}” -f (($_.FreeSpace/1GB));"GB";"/";(($_.Capacity/1GB));"GB"; } } $result += [PSCustomObject] @{ ServerName = "$computername" CPULoad = "$($AVGProc.Average)" Mempercentage = "$($mem.Memorypercentage)%" MemLoad = "$($OS.MemoryUsage)" CDrive = "$($vol.'C PercentFree')" DDrive = "$($dvol.'D PercentFree')" } $Outputreport = "Server Health Report" $Outputreport += "$(Get-Date -Format yyyy-MM-dd-hhmm)" $Outputreport += "Server IP $($Result.ServerName)" $Outputreport += "CPU Load $($Result.CPULoad)" $Outputreport += "Memory Utilization $($Result.Mempercentage)" $Outputreport += "Memory Available $($Result.MemLoad)" $Outputreport += "C Drive $($Result.CDrive)" $Outputreport += "D Drive $($Result.DDrive)" } $Outputreport += ping 192.168.110.1 #gateway $Outputreport += netstat -n $Outputreport | out-file "D:\health.txt"