Combreal

PS5-PS7_switch.ps1

May 29th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear()
  2. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Switch to PowerShell 7", {
  3.         function New-OutOfProcRunspace {
  4.             param($ProcessId)
  5.  
  6.             $ci = New-Object -TypeName System.Management.Automation.Runspaces.NamedPipeConnectionInfo -ArgumentList @($ProcessId)
  7.             $tt = [System.Management.Automation.Runspaces.TypeTable]::LoadDefaultTypeFiles()
  8.  
  9.             $Runspace = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace($ci, $Host, $tt)
  10.  
  11.             $Runspace.Open()
  12.             $Runspace
  13.         }
  14.  
  15.         $PowerShell = Start-Process PWSH -ArgumentList @("-NoExit") -PassThru -WindowStyle Hidden
  16.         $Runspace = New-OutOfProcRunspace -ProcessId $PowerShell.Id
  17.         $Host.PushRunspace($Runspace)
  18. }, "ALT+F5") | Out-Null
  19.  
  20. $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Switch to Windows PowerShell", {
  21.     $Host.PopRunspace()
  22.  
  23.     $Child = Get-CimInstance -ClassName win32_process | where {$_.ParentProcessId -eq $Pid}
  24.     $Child | ForEach-Object { Stop-Process -Id $_.ProcessId }
  25.  
  26. }, "ALT+F6") | Out-Null
Add Comment
Please, Sign In to add comment