Error: "The term 'reg' is not recognized as the name of a cmdlet"
This error may occur when using the GetSoftware call on a Windows device, and it appears in the Automox agent logs (found here: Location of Files Required by Automox).
Example Log Output:
2022/07/23 12:21:56 cmd_windows.go:183: runScript: Error in Wait exit status 90
status: 90
stdOut: Omitted
stdErr: At C:\ProgramData\amagent\execDir887431099\execcmd341723102.ps1:688 char:19
& reg load "HKEY_USERS\$userSID" "C:\Users\$userName\ ...
~~~
System.Management.Automation.CommandNotFoundException: The term 'reg' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Root Cause:
This error typically occurs because the reg.exe command is not accessible from the current environment. This may happen if the path to C:\Windows\System32\ is missing from the system's environment variables.
Solution: Add the System32 Path to Environment Variables
-
Open System Properties:
- Right-click the This PC or My Computer icon and choose Properties.
- Navigate to the Advanced System Settings tab.
- Click Environment Variables.
-
Edit the Path Variable:
- In the System Variables section, locate the Path variable and click Edit.
Add the following path to the list:
C:\Windows\System32\
- Ensure each path is separated by a semicolon (;).
-
Save and Exit:
- Confirm your changes by clicking OK on all windows.
- Restart your computer to apply the changes.
Additional Troubleshooting Steps
If adding the path does not resolve the issue, try the following:
-
Verify File Existence:
Confirm that reg.exe exists in the C:\Windows\System32\ directory. If not, you may need to restore it from a backup or perform a system repair. -
Check PowerShell Execution Policies:
Ensure your execution policies allow the script to run:
Get-ExecutionPolicy
- If the policy is restrictive, adjust it:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
- If the policy is restrictive, adjust it:
-
Run PowerShell as Administrator:
Open PowerShell with elevated permissions to ensure there are no restrictions due to user privileges. -
Inspect User Profile Configuration:
Some PowerShell profiles may override system-level settings. Temporarily bypass the profile by starting PowerShell with the -NoProfile flag:
powershell.exe -NoProfile
When to Contact Support
If the issue persists after following the above steps, contact Automox Support. Include the following details in your support ticket:
- Device Name and ID.
- Agent Log File (location details available in this article).