How can I fix my PowerShell script for moving files?

0
10
Asked By ScriptSorcerer42 On

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

Answered By CodeTraveler99 On

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.

ScriptSorcerer42 -

OMG, that was it. Thanks a lot!

Answered By PowershellGuru88 On

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.

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.