I have a PowerShell script designed to move files from one folder to another, and it runs with admin privileges. However, I'm encountering an issue when I execute it in PowerShell ISE. The first time I hit F5, I get the error saying "MoveThem: The term 'MoveThem' is not recognized as the name of a cmdlet, function, script file, or operable program". If I press F5 again after that, it runs without any issues. I've tried adding pauses and other checks like 'While Get Command not loaded', but they didn't help. Any ideas on how to fix this?
2 Answers
It sounds like you might be calling the function before it's defined. Make sure to define your function 'MoveThem' before any calls to it in your script. That should fix the error you're seeing.
Another thing to consider is to avoid using PowerShell ISE altogether as it's no longer actively supported. Try running your script in the standard PowerShell console instead.

OMG, that was it. Thanks a lot!