Why does my PowerShell script run into errors when calling a function?

0
8
Asked By CuriousCat42 On

I've got this basic PowerShell script aimed at moving files from one folder to another. I've been running it in PowerShell ISE with administrative privileges since I need elevated access for later parts of the script. However, there's a hiccup: when I press F5 to run the script, I get an error stating 'MoveThem: The term 'MoveThem' is not recognized as the name of a cmdlet, function, script file, or operable program.' It's odd because after that, if I hit F5 again, it works fine. I've tried adding pauses and even a 'While Get Command' check, but nothing seems to help. Any advice?

2 Answers

Answered By ScriptSage22 On

One common mistake is calling the function before it's defined. Make sure your function declaration is at the top of the script, like this:

Function MoveThem{...}
MoveThem
That should fix the error you're seeing!

CuriousCat42 -

OMG, that was it. fml Thanks!

Answered By HelpfulHarry89 On

You should really post your entire script to get better help. Also, it’s worth noting that PowerShell ISE isn't actively supported anymore, so that might be part of the issue. Just a thought!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.