Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell ISE not recognizing changes in the script

Tags:

powershell

I have been working in a script using Powershell ISE for a few months and for some reason, a weird issue started to happen today.

If I edit the script, then save and run it from the same ISE window/session, it seems the changes made has no affect. If I run the code again after close and reopen the ISE, then I see the effect of the changes.

That issue happens for every single change. I have rebooted the system and the issue still. How could it be?

like image 323
Cleber Marques Avatar asked Aug 11 '26 02:08

Cleber Marques


1 Answers

Check if you have the functions defined in the correct order in your file.

Powershell processes in order (top-down) so the function definition needs to be before the function call:

function email($text){
    #email $text
}

#Do things
foreach{
    email($_)
}

The ISE keeps the functions from the last run in memory, so if you have the function call above the function definition, it will run the version from the previous run.

I had the same problem and stumled upon the solution while searching another topic: Powershell script not recognizing my function

like image 81
keen4000 Avatar answered Aug 12 '26 21:08

keen4000



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!