Home | Catalogue | Robert's Blog
Last Updated: [2023-04-06 Thu 06:43]
Occasionally the following error will appear when attempting to run commands on Windows machines:
The term 'cmd' is not recognized as the name of a cmdlet
This is due to a Path variable being set incorrectly in the registry. This can happen with some poorly written automation, or a misbehaving application, however, it's fairly easy to fix, and I have provided a Powershell script to address this (Run as Administrator):
$registryPath = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
$registryValue = "Path"
If ((Get-Item -Path Registry::$registryPath).GetValueKind($registryValue) -ne "ExpandString") {
$pathData = (Get-Item -Path Registry::$registryPath).GetValue($registryValue)
Set-ItemProperty -Path Registry::$registryPath -Name $registryValue -Value $pathData -Type ExpandString
Write-Output "Registry key updated"
} else {
throw "Key has the correct type. Aborting"
}
You can also do this manually in Registry Editor:
regedit
as Administrator.HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
From there:
regedit
.DISCLAIMER: The information provided on this website is generated from my own notes and is provided "as is" and without warranties. Robert Ian Hawdon can not be held responsible for damages caused by following a guide published on this site. This website contains links to other third-party websites. Such links are provided as convienice of the reader. I do not endorce the contents of these third party sites.