r/PowerShell • u/UnBrewsual • Feb 02 '26
Solved Please fix my stupid script.
Its a simple function that moves files from one folder to another, powershell is running in Admin because I have elevated privledges later in the script.
The problem is: If I open Powershell ISE as admin, then press F5 to run, it will error saying "MoveThem: The term 'MoveThem' is not recognized as the name of a cmdlet, function, script file, or operable program.."
Just typing: MoveThem
Function MoveThem {...}
Here is the rub: After it errors, if I press F5 again, it runs without error.
Adding a pause does nothing.
Adding a While Get Command not loaded just death spirals.
14
u/HankMardukasNY Feb 02 '26
Function needs to be above where you call it
Function MoveThem{…} MoveThem
2
u/Katu93 Feb 02 '26
In the script do you have the function defined first? Sounds like you call the function before it is.
20
u/Medium-Comfortable Feb 02 '26
Post your script, it will enable others to help you. Don’t use ISE, it’s no longer actively supported. Just my 0.02 USD.
3
u/0x00040001 Feb 02 '26
Make sure the function block is above the line that calls said function.
2
u/pigers1986 Feb 07 '26
No script = no help
1
u/keith-kld Feb 04 '26
I have read some powershell scripts and found that functions are put on top while main program is placed at the bottom.