Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows PowerShell ISE running old version

I'm writing my PowerShell scripts with Windows PowerShell ISE. When I change someting in the script and run the script, not the last saved version of the script is executed but the older one. Only if I run the script a second time it uses the current version. What can I do to always run the newest version of the script?

like image 212
jlai Avatar asked Sep 26 '13 08:09

jlai


People also ask

Can you use PowerShell 7 in Ise?

Visual Studio Code (VSCode) with the PowerShell Extension is the supported scripting environment for PowerShell 7. The Windows PowerShell Integrated Scripting Environment (ISE) only supports Windows PowerShell.

Is PowerShell ISE discontinued?

The PowerShell ISE is no longer in active feature development. As a shipping component of Windows, it continues to be officially supported for security and high-priority servicing fixes. We currently have no plans to remove the ISE from Windows. There is no support for the ISE in PowerShell v6 and beyond.

How do I run a specific version of PowerShell?

When you start Windows PowerShell the newest version starts by default. To start Windows PowerShell with the Windows PowerShell 2.0 Engine, use the Version parameter of PowerShell.exe . You can run the command at any command prompt, including Windows PowerShell and Cmd.exe.

Can you run multiple versions of PowerShell?

Can I install multiple versions of PowerShell? No. If you try to install an older or newer version of Windows PowerShell, you might be able to replace the current version, but you cannot add. You cannot install any two versions of Windows PowerShell side-by-side or in sequence on the same computer.


1 Answers

This is a very old question, but I think I've stumbled across the same issue. In my case I've defined a function after invoking it. It appears to work, but only because "myfunc" still has the value from the previous invocation. If you change "Hello, World!", you'll find that the new value takes affect only on the second attempt.

Invoke-Command -ScriptBlock ${function:myfunc}

function myfunc() {
    Write-Host "Hello, World!"
}

To resolve the issue, simply define the function before you attempt to call it.

function myfunc() {
    Write-Host "Hello, World!"
}

Invoke-Command -ScriptBlock ${function:myfunc}
like image 144
Boinst Avatar answered Oct 20 '22 09:10

Boinst