Skip to content

/errors/powershell/term-is-not-recognized-as-the-name-of-a-cmdlet

PowerShell: The term 'x' is not recognized as the name of a cmdlet, function, script file, or operable program

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
PowerShell
exit code
1
versions
Windows PowerShell 5.1, PowerShell 7.x
os
windows, linux, macos

The term 'Get-Foo' is not recognized as the name of a cmdlet, function, script file, or operable program. means PowerShell found nothing with that name: no alias, function, cmdlet from an available module, script or executable in PATH. Check the spelling with Get-Command, then install or import the module that provides the cmdlet, or add the program to PATH. A script in the current folder must be called as .\script.ps1.

Reproduce it

powershell
'"hello from script"' | Set-Content hello.ps1
foreach ($cmd in 'Get-Foo123', 'hello.ps1', '.\hello.ps1') {
  try { & $cmd } catch { "$cmd -> $($_.Exception.Message)" }
}

Output

Get-Foo123 -> The term 'Get-Foo123' 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.
hello.ps1 -> The term 'hello.ps1' 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.
hello from script

hello.ps1 fails and .\hello.ps1 runs: PowerShell does not search the current folder, unlike cmd. In an interactive console it also prints a suggestion to use .\hello.ps1.

Find the command

powershell
Get-Command Get-ADUser -All          # is it anywhere on this machine?
Get-Command *mailbox* -Module ExchangeOnlineManagement
Get-Module -ListAvailable ActiveDirectory
$env:PATH -split ';'
SituationFix
Cmdlet from a module that is not installed (Get-ADUser, Get-MgUser, Connect-ExchangeOnline)install the module or Windows feature (RSAT for ActiveDirectory)
Module installed for PowerShell 7 only, running Windows PowerShell 5.1 (or the reverse)install it for that edition, or check $env:PSModulePath
Exchange Online cmdlet such as Get-Mailbox before connectingConnect-ExchangeOnline first; in EXO v3 these cmdlets are created by the connection
Program installed, new window not openedopen a new terminal so it reads the new PATH
Function defined in another scriptdot-source it: . .\functions.ps1
Linux or cmd habit (grep, ifconfig, dir /s)use the PowerShell cmdlet: Select-String, Get-NetIPAddress, Get-ChildItem -Recurse

Call a program with spaces in its path

A quoted path is a string, not a command. Use the call operator:

powershell
& 'C:\Program Files\Tool\tool.exe' --version

Without &, PowerShell prints the string instead of running the program.

Sources