Perfmon – create collector set with powershell

I have finally found a kind of “perfect” starting point with settings for my data collector sets in “Performance Monitor”. For the last year I have set up a number of collector sets, and  found it useful to organize these into monthly folders with “YYYY-MM and set up one BLG for each day. I normally set up a schedule with 12-16 hours, starting at 06:00 and ending around 22:00. This enables me to analyse performance issues in normal work hours, plus/minus a few hours.  I only set an “All-Day” schedule if I want to monitor the server performance during backup and nightly maintenance.

The following script is used to create the data collector set and start it. Download full script here.

  [string]$name = "MyCollectorSet"

$datacollectorset = New-Object -COM Pla.DataCollectorSet
$datacollectorset.DisplayName = $name;
$datacollectorset.Duration = 50400 ;
$datacollectorset.SubdirectoryFormat = 1 ;
$datacollectorset.SubdirectoryFormatPattern = "yyyy\-MM";
$datacollectorset.RootPath = "%systemdrive%\PerfLogs\Admin\" + $name ;

$DataCollector = $datacollectorset.DataCollectors.CreateDataCollector(0) 
$DataCollector.FileName = $name + "_";
$DataCollector.FileNameFormat = 0x1 ;
$DataCollector.FileNameFormatPattern = "yyyy\-MM\-dd";
$DataCollector.SampleInterval = 15
$DataCollector.LogAppend = $true;

$counters = @(
    "\PhysicalDisk\Avg. Disk Sec/Read",
    "\PhysicalDisk\Avg. Disk Sec/Write",
    "\PhysicalDisk\Avg. Disk Queue Length",
    "\Memory\Available MBytes", 
    "\Processor(_Total)\% Processor Time", 
    "\System\Processor Queue Length"
) ;

$DataCollector.PerformanceCounters = $counters

$StartDate = [DateTime]('2013-01-01 06:00:00');

$NewSchedule = $datacollectorset.schedules.CreateSchedule()
$NewSchedule.Days = 127
$NewSchedule.StartDate = $StartDate
$NewSchedule.StartTime = $StartDate

    $datacollectorset.Commit("$name" , $null , 0x0003) | Out-Null
catch [Exception] 
    Write-Host "Exception Caught: " $_.Exception -ForegroundColor Red 

If your SYSTEM account is not member of the local groups “Performance Log Users” and “Performance Monitor Users”, the following powershell commands can be run to add these memberships:

    $group = [ADSI]"WinNT://./Performance Log Users,group"

    $group = [ADSI]"WinNT://./Performance Monitor Users,group"

When a performance monitor data collector set is screated, this can be found under Task Scheduler under “\Microsoft\Windows\PLA”. It is very useful to make some minor changes to the settings of the data collector set that is not available from Performance monitor. If you want the data collector set to automatically start after server reboot, you should add a “At startup” trigger to the scheduled task.



4 thoughts on “Perfmon – create collector set with powershell

  1. Could you explain this as I’m sorta new to Powershell. How does this vary according to different parameters we may need. and how to write them?

    $counters = @(
    “\PhysicalDisk\Avg. Disk Sec/Read”,
    “\PhysicalDisk\Avg. Disk Sec/Write”,
    “\PhysicalDisk\Avg. Disk Queue Length”,
    “\Memory\Available MBytes”,
    “\Processor(_Total)\% Processor Time”,
    “\System\Processor Queue Length”
    ) ;

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s