Powershell

Marco Shaw asked recently on the PowerShell MVP mailing list if it would be possible to open a tab in the PowerShell V2 ISE (the GUI console which ships with CTP3) that would connect to a remote machine.  Turns out that it’s not that hard at all.  Ibrahim on the PowerShell team gave an answer which I”ll share with you.

Note: Vista or 2008 and PowerShell V2 CTP3 are required for WinRM (the remoting piece) to work, although we’re told this will be backported to XP and 2003 in the future.

Check out this screenshot, and the code to paste into your shell is just below.  In my example, I just connected to localhost, but you can connect to any remote box that is configured correctly.

image

$computername = Read-Host
$psise.OpenedRunspaces.Add()
sleep 3 # wait for profile to load
$psise.OpenedRunspaces[1].Execute("Enter-PSSession –computerName $computername")
$psise.OpenedRunspaces[1].DisplayName = "REMOTE: $computerName"

Thanks to Ibrahim, and to Marco who was too busy to blog this himself.  :)

: http://halr9000.com/article/690

2009-01-27 19:05:26

So the next question is … for $20 … can you open a tab that remotes into your own PC, but in an elevated context?

2009-01-27 21:36:43

Iono, I use XP. :)

2009-01-27 22:32:03

Well, _you’re_ an MVP with that obviously awesome mailing list … find out! :^P

2009-02-01 23:07:31

[...] How to open a remote powershell tab in ISE (V2 CTP3) [...]

2010-03-15 13:25:42

This doesn’t exist anymore in RTM…. OpenedRunSpaces seems to be PowerShellTabs
$psise.PowerShellTabs.Add()

2010-03-15 13:27:27

I take that back… looks like it’s all completely changed… at least I have something new to play with and break….

2010-03-15 14:30:49

I take it back again… it does work w/ the new names…. I had to use NewScriptBlock though because it doesn’t invoke if you just pass a string:

$computername = Read-Host “Enter Remote Computer Name”
$tab = $psise.PowerShellTabs.Add()
sleep 3
$tab.Invoke($ExecutionContext.InvokeCommand.NewScriptBlock(“Enter-PSSession -computername $computername”))
$tab.DisplayName = “REMOTE: $computerName”

2010-11-17 11:39:41

[...] can either open a new tab to a remote shell, or use winrm. These are both “native”. November 10, 2009 9:50 am Valvaris I [...]

2011-08-20 23:58:01

[...] can either open a new tab to a remote shell, or use winrm. These are both [...]

Reiner
2012-01-20 08:14:22

I’m trying to use this technique to connect across domains. I’m trying to avoid getting an authentication prompt, but don’t know how? Any help available on this? Thanks lots.

$secpasswd = ConvertTo-SecureString “Password” -AsPlainText -Force
$mycreds = New-object -typename System.Management.Automation.PSCredential(“Login@Domain.com”,$secpasswd)

$computername = Read-Host “Enter Remote Computer Name”
$tab = $psise.PowerShellTabs.Add()
sleep 3
$tab.Invoke($ExecutionContext.InvokeCommand.NewScriptBlock(“Enter-PSSession -computername $computername -credential $mycreds”))
$tab.DisplayName = “REMOTE: $computerName”

  • Microblog

  • Recent Posts

  • Recent Comments

  • meta

  • PowerShell Blogroll