Sometimes we need monitor, CPU, Memory, Network utilization of a server or servers for a certain period of time. Maybe you want to know what happens when users hit your servers at 9:00 am, 12:00 pm and 2:00 pm, then you want to correlate the impact on the servers based on the amount of users.
With PowerShell you can create counters and monitor what you need during that period and everything done though the command line. If you want to know what counter make the most sense to monitor you can check this article TechNet article.
You can also explore perfmon counter from the command line
Get-Counter -ListSet *
As you can see you get a lot of counters that are difficult to read. To make it easier we can use out-gridview
Get-Counter -ListSet * | Out-GridView
Now you can search for a counter, look at the description and the path that can be used on the script to monitor performance data.
When creating daily counters we need to make sure to append the date and time to the .blg file. The easiest way is to accomplish this is using get-date like such
$TimeStamp = get-date -Format MMddyy’T’HHmm
To start collecting some counters in a continuous manner run this.
If you run this,the PowerShell ISE window will be lock running that task, so we can run this script as a job using the following code
Now the job is running under the name counter with ID number 5
To check if the job is running run Get-Job -State Running and you can also check the .blg file
When you are done collecting logs you can stop the job with stop-job and make sure to remove the job afterwards with remove-job
If you open the file, you will see all the performance metrics on it
You can use invoke-command to run this across multiple servers or use a schedule task to call the script and run it as a background job. You can also specify a maximum number of samples instead of being continuous