I find myself typing the following 3 lines over and over every day:
$ip = "220.127.116.11"
$s = New-PSSession -ComputerName $ip -Credential ~\Administrator
So, I decided to put an end to this, and not only save time typing, but save my wrists from carpel tunnel syndrome 🙂
Now, I type:
If I exit the remote session and need to re-enter, I type:
$global:ip = $ipAddr
$global:s = New-PSSession -ComputerName $global:ip -Credential ~\Administrator
- The variables have global scope, so that they would persist in your session, if you ever need to reuse them ($ip and $s), say for a copy operation or something.
- Put these functions into your profile, so they get automatically loaded every session.
- You’ll notice that these functions do not adhere to the PowerShell Verb-Noun naming standards. That’s because these are quick-and-dirty accelerator functions which really improve my productivity, and are not functions that I’ll be sharing with the world.
When Andrew saw this function, he wanted me to extend it to keep track of more than one session, so that you can ultimately say: enter 3 (for the third session). What do you guys think?