Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Combining scripts/functions to get CPU usage, memory usage and free disk space

$
0
0
Could you help me combine these three scripts to a format that's like this

   
ComputerName     CPUUsageAverage    MemoryUsage    C PercentFree
xxx                                                  12            50%              30%



 The way I execute this is:
Get-content '.\servers.txt' | Get-CPUusageAverage



Here are the scripts:

CPU

 
  Function Get-CPUusageAverage    {    $input|Foreach-Object{Get-WmiObject -computername $_ win32_processor | Measure-Object -property LoadPercentage -Average | Select Average}    }



Memory

       
Function get-MemoryUsage    {    $input|Foreach-Object{    gwmi -Class win32_operatingsystem -computername $_ |    Select-Object @{Name = "MemoryUsage"; Expression = { “{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize) }
    }    }    }



C PercentFree

 
  Function get-CPercentFree    {    $input|ForEach-Object{      Get-WmiObject -Class win32_Volume -ComputerName $_ -Filter "DriveLetter = 'C:'" |      Select-object @{Name = "C PercentFree"; Expression = { “{0:N2}” -f (($_.FreeSpace / $_.Capacity)*100) } }
     }      }







Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>