Intune, ConfigMgr, PowerShell and more...
This post is the first of three for automating common debugging tools on Windows endpoints.
Earlier this year I came across a scenario of an application dropping connections. This was occuring across many hundreds of users and sporadically. Typically, I would attempt to recreate the issue so I could debug, but that was not possible here. I needed a way to be ready for the drop to occur and have all debugging tools setup proactively across a large number of users.
We use ConfigMgr to run scripts on workstations from a central location and it worked well in this scenario.
Invoke-CMScript -CollectionId <CollectionId> -ScriptGuid <scriptguid>
This script is fairly basic, mostly just took figuring out how to interact with a Data Collector Set using logman.exe and make sure it didn’t clobber the existing DCS that is running.
Special thanks to Aussie Rob SQL, Jonathan Medd, and Rabi Achrafi for the example scripts I found online. References are in the script help text. Also thanks to my co-workers Darren Chinnon and Raul Colunga who helped put this together.
Edit the lines below to personalize as needed
$DCSName = 'PerfMonExample'
$DCSCheck = & logman query $DCSName # Query if DCS already exists
if ($DCSCheck[1] -like "*$($DCSName)") {
Write-Output 'DCS found!'
if ($DCSCheck[2] -like '*Running') {
Write-Output 'Trace running, exiting...'
} else {
Write-Output 'Trace not running, starting...'
& logman start $DCSName
}
} else {
Write-Output 'DCS not found, creating...'
# Create the Data Collector Set
$DCS = New-Object -COM Pla.DataCollectorSet
$DCS.DisplayName = $DCSName
$DCS.SetXml($DCSTemplate)
$DCS.Commit("$DCSName" , $null , 0x0003)
# Start the data collection
Write-Output 'Starting the DCS!'
$DCS.start($false)
}
Github Link: Start-PerfmonCapture.ps1
The script gives a little output for validation, not much though. This is mostly for validation during testing.
Starting the script, there may be additional output from logman.exe for the initial run
Starting the script when DCS is already running
Starting the script when DCS is not running
Overall, this process worked well and met the need. It wasn’t the first time I had to use Perfmon and it won’t be the last. Up next, Wireshark.