次の方法で共有


Remoting to Nano Server made easy

I find myself typing the following 3 lines over and over every day:

$ip = "1.2.3.4"

$s = New-PSSession -ComputerName $ip -Credential ~\Administrator

Enter-PSSession $s

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:

go "1.2.3.4"

If I exit the remote session and need to re-enter, I type:

enter

The functions:

function go($ipAddr)

{

    $global:ip = $ipAddr

    $global:s = New-PSSession -ComputerName $global:ip -Credential ~\Administrator

    Enter-PSSession $global:s

}

function enter

{

    Enter-PSSession $global:s

}

Notes:

  • 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?

 ref@

Comments

  • Anonymous
    April 14, 2016
    Its a great idea to be able to store a few sessions just like the Linux screen command.
    • Anonymous
      May 04, 2016
      @Ryen, thanks for the feedback
  • Anonymous
    April 30, 2016
    I agree also with Ryen
    • Anonymous
      May 04, 2016
      @Wojciech, thanks for the feedback