18 Sessions: Remote control with less work

 

In chapter 13, we introduced you to PowerShell’s remoting features. In that chapter, you used two primary cmdlets—Invoke-Command and Enter-PSSession—to access both one-to-many and one-to-one remote control. Those two cmdlets work by creating a new remoting connection, doing whatever work you specify, and then closing that connection.

There’s nothing wrong with that approach, but it can be tiring to have to continually specify computer names, credentials, alternative port numbers, and so on. In this chapter, you’ll look at an easier, more reusable way to tackle remoting. You’ll also learn about a third way to use remoting called implicit remoting, which will allow you to add proxy commands by importing a module from a remote machine into your remote session.

Anytime you need to connect to a remote computer, using either Invoke-Command or Enter-PSSession, you have to at least specify the computer’s name (or names, if you’re invoking a command on multiple computers). Depending on your environment, you may also have to specify alternative credentials, which means being prompted for a password. You might also need to specify alternative ports or authentication mechanisms, depending upon how your organization has configured remoting.

None of that is difficult to specify, but it can be tedious to have to repeat the process again and again. Fortunately, we know of a better way: reusable sessions.

18.1 Creating and using reusable sessions

18.2 Enter-PSSession with session objects

18.3 Invoke-Command with session objects

18.4 Implicit remoting: Importing a session

18.5 Using disconnected sessions

18.6 Lab

18.7 Lab answers

18.8 Further exploration