Contents

PowerShell for IT Professionals [#10] – Remote management with PowerShell

Contents

In this lesson we’re going to learn how to do one-to-one and one-to-many remote management with PowerShell. There’s no need for telnet, ssh or psexec as PowerShell has its own protocol that’s built in right into Windows. We will look at how to create interactive sessions and send commands to multiple servers at once.

Exercises

  1. With Enter-PSSesion, Remote to remote server and  restart “Windows update” service
  2. With Invoke-Command find out the remote computers last boot up/startup time
  3. List all running processes on remote server without using Enter-PsSession or Invoke-Command
  4. If you have a Domain Controller available, use Invoke-Command to list all computers on that network (you can use * for filter), remember that you need to provide all necessary parameters with your command in the script block so command just runs and doesn’t prompt for any additional information.

Notes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Enable-Psremoting

Enter-PSSesion ps-svr1

Hostname
Get-Service
GIP

# I can even run commands that are not available on my source machine

Get-ADDomainController
Get-ADUser

Exit or Exit-PSSession

# Caution about double hoping

Invoke-Command

Invoke-Command -computerName ps-svr1 -command  { get-service}

# Invoke command executes commands on the remote comptuers and brings back the results

# Can you tell a difference?

Invoke-Command -computerName ps-svr1 -command  { get-service | Where {$_.status -eq 'stopped' } }

Invoke-Command -computerName ps-svr1 -command  { get-service } | Where {$_.status -eq 'stopped' }

# -ComputerName in the commandlet

Get-Service -ComputerName ps-svr1

Invoke-Command -computerName ps-svr1 -command  { get-service  }

# they look the same, but are they?

Get-Service -ComputerName ps-svr1 | GM

Invoke-Command -computerName ps-svr1 -command  { get-service  } | GM