Configuring Windows Task Scheduler to run daily Performance Monitor Data Collector Set.

In my previous blog, I posted a PowerShell script that can configure a Data Collector Set, with Data Collectors for the server and all MS SQL instances.
As part of my testing, I found that setting up Windows Task Scheduler to restart daily at 5am, that the Perfmon data collector set was not restarting.

The specific part in my previous script that sets up this task is:

 Invoke-Command -ComputerName $Server -ArgumentList $DCSName -ScriptBlock {
            param($DCSName)
            $Trigger = @()
            #Start when server starts.
            $Trigger += New-ScheduledTaskTrigger -AtStartup 
            #Restart Daily at 5AM. Note: I have not used Segments.
            $Trigger += New-ScheduledTaskTrigger -Weekly -DaysOfWeek Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday -at 05:00
            $Path = (Get-ScheduledTask -TaskName $DCSName).TaskPath
            #This setting in the Windows Scheduler forces the existing Data Collector Set to stop, and a new one to start
            $StopExisting = New-ScheduledTaskSettingsSet
            $StopExisting.CimInstanceProperties['MultipleInstances'].Value=3
            Set-ScheduledTask -TaskName $DCSName -TaskPath $Path -Trigger $Trigger -Settings $StopExisting | Out-Null
        }

If all went well, in Task Scheduler under Task Scheduler Library\Microsoft\Windows\PLA you should see your task as follows.

Triggers

Settings

Note in the settings, “If the task is already running, the following rule applies:” is set to Stop the existing instance.

Herein is the issue. When the next stop command is issued, the collector takes time to stop. If you check the task history, it looks like this.
This is the default sort so your entries may be in a different order

We see the task stop (as configured) and then start, but then the action completes, and the task completes / stop. This is a problem as we want the collector to keep running.

So… what’s going on. Well, lets open up Event Viewer.
We want to go into Application and Services Logs\Microsoft\Windows\Diagnosis-PLA and select the Operational log.

You should see an error.
Data collector set SQLAudit failed to start as WORKGROUP\xxxxx$ with error code 0x803000AA.
Going into details you’ll see :

On the Microsoft page, https://msdn.microsoft.com/en-au/library/cc238505.aspx, error 0x803000AA indicates PLA_E_DCS_IN_USE, or the Data Collector Set is already running.

I’ll show you how I worked around this in my next blog.

Leave a Reply

Your email address will not be published. Required fields are marked *