I’m using GFI MAX Remote Management to deploy some PowerShell scripts to servers. The scripts need access to a new directory I set up, C:\Scripts\PowerShell, so I used a PowerShell command to add that path to the Path environment variable in the machine scope.
$ScriptsPath = 'C:\Scripts\PowerShell\' $CurrentMachinePath = [Environment]::GetEnvironmentVariable("Path", ` [System.EnvironmentVariableTarget]::Machine) [Environment]::SetEnvironmentVariable( "Path", $CurrentMachinePath + ";" + ` $ScriptsPath, [System.EnvironmentVariableTarget]::Machine )
I couldn’t figure out why my scripts weren’t running. When I checked the path from a command prompt, it looked fine:
Finally it occurred to me that since the MAX RM agent runs in the Local System account, maybe the Path won’t be updated until the computer reboots. To check, I ran a small PowerShell script from MAX RM to see what the Local System account sees as the environment:
Get-ChildItem env: | Out-String -Width 4096 -Stream ` | ForEach-Object { $_.TrimEnd() }
Checking the results in the MAX RM dashboard, I see that sure enough, the Path has not been updated, and it runs in the machine context (USERNAME = MachineName$):
So, reboot and voila, the path has now been updated:
…and scripts that depend on the path are running.