Term is Not Recognized in PowerShell

Leave a comment

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:

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

Leave a Reply

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