Home › PowerShell › Term is Not Recognized in PowerShell
PowerShell · Jan 19, 2018

Term is Not Recognized in PowerShell

In PowerShell, you may encounter the error “The term 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.”

Let’s look at how to fix this.

In the example below, I have a function called Add2, which adds 2 numbers:

The code:

$num1 = 5
$num2 = 10

Add2 $num1 $num2

function Add2($num1, $num2) {
    $num3 = [int]$num1 + [int]$num2
    Write-Output $num3
}

The problem here is PowerShell is not aware of the function at the time of running. If you were to run this a second time, you probably won’t encounter the error as the function is now declared after the first iteration.

Changing the order of this, where the function is written first:

function Add3($num1, $num2) {
    $num3 = [int]$num1 + [int]$num2
    Write-Output $num3
}

$num1 = 5
$num2 = 10

Add3 $num1 $num2

Now when running this, we do not get the error:

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Carl de Souza
KEEP LEARNING. KEEP BUILDING.

Explore AI, agents & Microsoft technology.

I share practical ideas, tutorials, and videos about AI, AI agents, Microsoft technologies, and the Power Platform.