Skip to content
ohsudo, Home
Windows

PowerShell "is not recognized as the name of a cmdlet": find out why it can't see the command

Fix PowerShell "is not recognized as the name of a cmdlet, function, script file": check the spelling, PATH, the .\ prefix for scripts and missing modules, step by step.

Beginner3 min readApplies to Windows PowerShell 5.1 · PowerShell 7 · Windows 10 · Windows 11 · Windows Server

by OhSudo ·

PS C:\> terraform version
terraform : The term 'terraform' 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.

PowerShell looked everywhere it knows, and didn’t find anything by that name. So the question is why it isn’t looking in the right place. There are four usual answers: a typo, a folder that isn’t in PATH, a script in the current folder, or a module that isn’t installed.

TL;DR

Terminal window
Get-Command terraform -ErrorAction SilentlyContinue # does it know the name?
$env:Path -split ';' # where does it look?
.\deploy.ps1 # a script here needs .\
Get-Module -ListAvailable ActiveDirectory # is the module installed?

1. A script in this folder

This catches everyone once. You can see the file, and PowerShell says it doesn’t exist:

Terminal window
PS C:\scripts> deploy.ps1
deploy.ps1 : The term 'deploy.ps1' is not recognized ...

For safety, PowerShell doesn’t run things from the current folder unless you say so. It even suggests this at the end of the message. Add .\:

Terminal window
.\deploy.ps1

If that gives running scripts is disabled on this system, then this problem is solved, and the next one has started: see that article.

A path with spaces needs quotes, and also &, which means “run this”:

Terminal window
& "C:\Program Files\MyTool\tool.exe" --version

2. A program that isn’t in PATH

PATH is the list of folders searched for programs. You installed a tool, and its folder isn’t in the list. Find the file first:

Terminal window
Get-ChildItem -Path "C:\Program Files", "$env:LOCALAPPDATA" -Filter terraform.exe -Recurse -ErrorAction SilentlyContinue | Select-Object FullName

To try it in this window only:

Terminal window
$env:Path += ";C:\Tools\terraform"
terraform version

To keep it for your user:

Terminal window
[Environment]::SetEnvironmentVariable('Path', [Environment]::GetEnvironmentVariable('Path', 'User') + ';C:\Tools\terraform', 'User')

Use 'Machine' instead of 'User', from an administrator window, to apply it to all users.

Open a new window afterwards. A window that’s already open keeps its old PATH, and that’s why a tool you’ve just installed often isn’t found until you do. For a service or a scheduled task, you may have to restart it, or the machine.

Don’t use setx PATH "%PATH%;...", which you’ll see in old guides. It merges your user and system values into one, and cuts the result off at 1024 characters, which can break your PATH.

3. A module that isn’t there

Cmdlets come from modules. The name has a verb and a noun, such as Get-ADUser, and it isn’t found because that module isn’t installed:

Terminal window
Get-Module -ListAvailable ActiveDirectory
Get-Command Get-ADUser -All

Some come with a Windows feature, and others from the PowerShell Gallery:

Terminal window
# Active Directory, on Windows 10 and 11
Add-WindowsCapability -Online -Name Rsat.ActiveDirectory.DS-LDS.Tools~~~~0.0.1.0
# Active Directory, on Windows Server
Install-WindowsFeature RSAT-AD-PowerShell
# From the Gallery
Install-Module Az -Scope CurrentUser

Between versions: Windows PowerShell 5.1 and PowerShell 7 keep modules in different folders, so a module can work in one, and not in the other. See which one you’re in:

Terminal window
$PSVersionTable.PSVersion

Some old commands are gone from PowerShell 7 altogether, such as Get-WmiObject. Use Get-CimInstance instead.

4. A typo, or a Linux habit

Check the spelling with a wildcard, which also tells you what really exists:

Terminal window
Get-Command *firewall*

Commands from another system are common here:

You typed On Windows
sudo Open an administrator window (gsudo, or sudo on recent Windows 11, if turned on)
grep Select-String
touch New-Item file.txt
which Get-Command
export VAR=1 $env:VAR = 1
apt, yum winget

5. It works by hand, and not in a task

Scheduled tasks and CI agents can run under another user, and they get that user’s PATH. In a script, use the full path. A command with a typo inside a script gives the error on that line, so read the line number in the message.

Warning

Don’t copy an .exe into C:\Windows\System32 to make this go away. It works, and it mixes your tools in with the system’s, which makes updates and security reviews harder. Add a folder to PATH instead.

Shell, we have a problem!

Similar, but different: running scripts is disabled on this system is the execution policy. Access is denied means it was found, and you’re not allowed to run it. On Linux, the same problem says command not found, and on macOS, see command not found: brew. If Install-Module itself fails with Unable to resolve package source, see that article.

Found this useful? Share it.

Found a mistake? Let us know at contact@ohsudo.com.

Articles

Related articles