Skip to content

Instantly share code, notes, and snippets.

@adamdriscoll
Last active February 19, 2021 10:27
Show Gist options
  • Save adamdriscoll/ca01e7dcaf6fed5138ceb686e02ca0fd to your computer and use it in GitHub Desktop.
Save adamdriscoll/ca01e7dcaf6fed5138ceb686e02ca0fd to your computer and use it in GitHub Desktop.
Run PowerShell 7 in the ISE
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear()
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Switch to PowerShell 7", {
function New-OutOfProcRunspace {
param($ProcessId)
$ci = New-Object -TypeName System.Management.Automation.Runspaces.NamedPipeConnectionInfo -ArgumentList @($ProcessId)
$tt = [System.Management.Automation.Runspaces.TypeTable]::LoadDefaultTypeFiles()
$Runspace = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace($ci, $Host, $tt)
$Runspace.Open()
$Runspace
}
$PowerShell = Start-Process PWSH -ArgumentList @("-NoExit") -PassThru -WindowStyle Hidden
$Runspace = New-OutOfProcRunspace -ProcessId $PowerShell.Id
$Host.PushRunspace($Runspace)
}, "ALT+F5") | Out-Null
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Switch to Windows PowerShell", {
$Host.PopRunspace()
$Child = Get-CimInstance -ClassName win32_process | where {$_.ParentProcessId -eq $Pid}
$Child | ForEach-Object { Stop-Process -Id $_.ProcessId }
}, "ALT+F6") | Out-Null
@noeffort3
Copy link

I continue to receive the error:

MethodInvocationException: 
Line |
  16 |          $Host.PushRunspace($Runspace)
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "PushRunspace" with "1" argument(s): "Specified method is not supported."

when I use the "Add-ons" > "Switch to PowerShell 7"

is there an expectation that this is a "known issue"?

@ISeeTWizard
Copy link

I have the same problem like noeffort3

@Floriszz
Copy link

Floriszz commented Aug 18, 2020

I get the same error after running PushRunspace.
But running the PS7ISE.ps1 in a clean PowerShell ISE elevated session does not throw any erros. But using the swithing from the 'Add-ons' menu(ALT-F5) afterwards, gives me the following error popup. Using $PSversiontable does show me version 7.0.3 though and the help menu seems to switch as well.
ps7isePopupError

@jamieoneill
Copy link

Same as @Floriszz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment