23
POWERSHELL 2.0 REMOTING UK POWERSHELL USER GROUP Jonathan Medd

PowerShell 2 remoting

Embed Size (px)

Citation preview

Page 1: PowerShell 2 remoting

POWERSHELL 2.0 REMOTING

UK POWERSHELL USER GROUP

Jonathan Medd

Page 2: PowerShell 2 remoting

I have a dream...........

Page 3: PowerShell 2 remoting

Ben Pearce, Microsoft PFE, gave me that dream in Oct 2008.......

Page 4: PowerShell 2 remoting

......and now that dream has come true!PowerShell Remoting is here and I can manage my entire Windows estate from the comfort of my Home Cinema.

Page 5: PowerShell 2 remoting

PowerShell 2.0 – New Cmdlets with Remoting Functionality PowerShell 1.0 only had Get-WmiObject -

Computername PowerShell 2.0 has 35 cmdlets with

ComputerName paramter Examples: Get-Service, Restart-Computer,

Write-EventLog Use protocols such as RPC & DCOM Find them with Get-Command | Where-

Object {$_.definition -match 'computername'}

Page 6: PowerShell 2 remoting

Software Requirements for Full-Fat Remoting

Typically HTTP on port 5985, open for WinRM 2.0. HTTPS on (5986)

PowerShell 2.0 and WinRM 2.0 So either:

Windows Server 2008 R2 or Windows 7Windows Server 2003 or Windows XP and

later with the Windows Management Framework Installed which includes PowerShell 2.0 and WinRM 2.0

Page 7: PowerShell 2 remoting

Enable-PSRemoting

Run as administrator Confirmation of changes

Page 8: PowerShell 2 remoting

Additional Requirements if in Workgroup not Domain If OS is XP then set Network Access: Sharing and

Security Model for local accounts) to Classic. Then, for any Windows Operating System, including

Windows XP, you will need to add the names of the remote computer(s) into the TrustedHosts setting of WinRM

Set-Item WSMan:localhost\Client\TrustedHosts -value ServerName

Page 9: PowerShell 2 remoting

Enable via Group Policy

Allow automatic configuration of listeners Computer Configuration\Policies\Administrative Templates\

Windows Components\Windows Remote Management\WinRM Service\

Page 10: PowerShell 2 remoting

Manual Firewall Settings

Enable Windows Remote Management

Page 11: PowerShell 2 remoting

Interactive PowerShell Remoting

Enter-PSSession –ComputerName Server01

Similar to Telnet / SSH Kerberos authentication by default,

encryption can be added with SSL Exit-PSSession when finished.

Session is torn down at this point

Page 12: PowerShell 2 remoting

Interactive PowerShell Remoting Demo

Page 13: PowerShell 2 remoting

If we stopped at this point even this interactive story would be great……..

30 years of catch-up on remote command line management

Page 14: PowerShell 2 remoting

SSH is so 2007.....

Persistent PowerShell Remoting

Page 15: PowerShell 2 remoting

Persistent PowerShell Remoting

Let’s create multiple sessions and store them in a variable $sessions

$sessions = New-PSSession –ComputerName (Get-Content Servers.txt)

Can be accessed by cmdlets like Enter-PSSession or Invoke-Command

Are maintained after the session has been used, until timeout period expired

Page 16: PowerShell 2 remoting

Basic Session Options

New-PSSession Parameters: -Credential: e.g. Domain01\User01 -Name: a friendly name to refer to them

with -Port: alternate port number to use -ThrottleLimit: max number of outbound

sessions from this command, 32 by default Other parameters are available, check Get-

Help!

Page 17: PowerShell 2 remoting

Advanced Session Options

New-PSSessionOption Parameters: -IdleTimeout: Default is 4 mins -OpenTimeout -OperationTimeout -NoCompression Other parameters are available, check

Get-Help! Used via New-PSSession -

SessionOption

Page 18: PowerShell 2 remoting

Advanced Session Options Set at the Destination

Register-PSSessionConfiguration Create customised session

configurations to present to remote connections.

-StartupScript: most interesting parameter

Used via New-PSSession -ConfigurationName

Page 19: PowerShell 2 remoting

Using Persistent Sessions

Invoke-Command –Session $sessions –ScriptBlock {Get-Culture}

Note the PSComputerName Property returned Invoke-Command –Session $sessions –

FilePath C:\Scripts\QueryServer.ps1 You can now run any existing script against

all your remote servers

Page 20: PowerShell 2 remoting

If you’re using Windows and not retiring in the next

12 – 18 months, you need to learn PowerShell!

Page 21: PowerShell 2 remoting

Implicit PowerShell Remoting

Use Management Tools from remote servers on your client workstation

No need to install modules locally Import-PSSession –Session $session

–Module ActiveDirectory All cmdlets from Active Directory

module now available on local workstation

Page 22: PowerShell 2 remoting

Obligatory Cloud Slide

Exchange Online (BPOS) $LiveCred = Get-Credential $Session = New-PSSession -ConnectionUri

https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection

Import-PSSession $Session A Cloud Service Provider can supply you

with the tools you need to manage their service with no local installation required

Page 23: PowerShell 2 remoting

Links

Simple-Talk Article http://www.simple-talk.com/sysadmin/powershell/new-remoting-features-in-powershell-2.0/

Administrators Guide to PowerShell Remoting http://powershell.com/cs/media/p/4908.aspx

Layman’s Guide to PowerShell Remoting http://www.ravichaganti.com/blog/?p=1305