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:
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