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, 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 = (Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment').GetValue('PATH', $null, 'DoNotExpandEnvironmentNames') -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.

We need to use SetEnvironmentVariable here instead of just setting $env:Path directly so the changes are persisted beyond the current session.

1
2
3
4
$CCMPath = 'C:\Windows\CCM'
$Paths = (Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment').GetValue('PATH', $null, 'DoNotExpandEnvironmentNames') -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 CM Trace from the Run box