Here’s a neat trick to make it easier to launch CMTrace (and smscfgrc.cpl) from the Run box and command line: Add the ConfigMgr client path to the PATH variable! Let’s do it via a configuration item:


Detection Script: To detect if it is already present, we get the existing contents of the PATH variable via the GetEnvironmentVariable method (more on this later), break it down into an array, and then loop through all of the entries, looking for a match.

1
2
3
4
5
6
7
8
9
$Compliant = $False
$CCMPath = 'C:\Windows\CCM'
$Paths = [System.Environment]::GetEnvironmentVariable('PATH') -split ';'
foreach ($Path in $Paths) {
    if ($Path -eq $CCMPath) {
        $Compliant = $True
    }
}
return $Compliant

Remediation Script: To remediate the configuration, we combine the contents of the current PATH variable, add the CCM directory to it, and use the SetEnvironmentVariable method to save the changes.

The reason we need to use SetEnvironmentVariable and not just setting $env:Path directly is so the changes are persisted beyond the current session. Because of this, I chose to also use GetEnvironmentVariable to remain consistent.

1
2
3
4
$CCMPath = 'C:\Windows\CCM'
$Paths = [System.Environment]::GetEnvironmentVariable('PATH') -split ';'
$NewPath = ($Paths + $CCMPath) -join ';'
[System.Environment]::SetEnvironmentVariable('PATH', $NewPath, [System.EnvironmentVariableTarget]::Machine)

Now you can do stuff like this without having to fully qualify the path or browsing to it!

Running cmtrace from the Run box