Chapter 18. Sessions: remote control, with less work

 

Back in chapter 10, I 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. Each of those cmdlets worked by creating a new remoting connection, doing whatever work you specified, 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, we’ll look at an easier, more reusable way of tackling remoting. You’ll also learn about a third way of using remoting that will really come in handy.

18.1. Making PowerShell remoting a bit easier

Anytime you need to connect to a remote computer, using either Invoke-Command or Enter-PSSession, you have to at the very 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 remoting is configured in your organization.

None of that is difficult to specify, but it can be tedious to have to do so again and again and again. Fortunately, there’s a better way: reusable sessions.

18.2. Creating and using reusable sessions

18.3. Using sessions with Enter-PSSession

18.4. Using sessions with Invoke-Command

18.5. Implicit remoting: importing a session

18.6. Lab

18.7. Ideas for on your own