58

Powershell et les techniques de remoting

Embed Size (px)

DESCRIPTION

Le but de cette session est d'apporter un point éclairé sur l'ensemble des possibilités de remoting utilisables par Powershell. Speakers : Fabien Dibot (Vivalto Santé), Carlo Mancini (STMicroelectronics)

Citation preview

Page 1: Powershell et les techniques de remoting
Page 2: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

PowerShell et les techniques de remoting

Carlo Mancini - MVP Powershell - STMicroElectronicsFabien Dibot - Ingénieur Systèmes - Vivalto Santé

@fdibot - @sysadm2010

Page 3: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

Depuis votre smartphone sur :http://notes.mstechdays.fr

De nombreux lots à gagner toute les heures !!!Claviers, souris et jeux Microsoft…

Merci de nous aider à améliorer les Techdays !

Donnez votre avis !

Page 4: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

POWERSHELL REMOTING

Page 5: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

1. Un peu d’histoire2. WinRM3. Les Sessions4. Common Information Model

SOMMAIRE

Page 6: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

UN PEU D’HISTOIRE

Page 7: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Montée en puissance de:– Windows 7 (45% du marché)– Windows  8 (10%)

PowerShell, deux constats et un peu d’histoire

• Microsoft 'big shift': de la GUI vers Powershell

Page 8: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

L’évolution de Powershell RemotingAvant

PowershellPowershell 1.0 Powershell 2.0 Powershell 3.0

Remote Desktop Connection

(RDP)

Sysinternals PsTools

• PsExec• PsList• PsFile

Logiciel tiers

Get-WMIObject -Computername

Pas de paramètre

–Credential

Protocole DCOM/RPC

Paramètre –ComputerName dans 35 cmdlets• Get-Process• Get-Service• Restart-Computer

• Get-WinEvent

Remoting

Cmdlets CIMGet-CIMInstance

Sessions deconnectées

Sessions robustes

Remoting implicite

Windows PWA

Page 9: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

Powershell Remoting, sauce 1.0…

... c'était du bricolage...

Page 10: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

Le problème avec DCOM/RPC

Get-WMIObject

Page 11: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• le parefeu gagne...

RPC/DCOM vs Parefeu

Page 12: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Exploite le service WinRM– WinRM 1.0

• installé par défaut sur Vista• Ports 80 et 443

– WinRM 1.1• sur Vista SP1 et 2008 SP1• installable sur XP SP2, 2003 et 2003 R2

– WinRM 2.0• sur Seven et sur 2008 R2• Installable sur XP SP3, Vista (SP1 ou SP2), et 2008 (SP1 ou SP2)• Ports 5985 (http) et 5986 (https)

• Introduit la notion de Session

Le nouveau paradigme

Page 13: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

WINRM

Page 14: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Windows Remote Management• Basé sur le standard WS-Man (Web

Services for Management)• S’appuie sur SOAP • Firewall-friendly

WinRM

Page 15: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

Architecture et EndPoints

Station de travail

WS-MAN

Serveur distant

Service WinRMhttp

listener

EndpointPowershell 64-bit

EndpointPowershell 32-bit

Autre Endpoint

Powershell.exe Powershell.exe ....exe

Page 16: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Communication chiffrée entre les machines :• Utilisation des jetons Kerberos.• NTLM Pour lancer des scripts et/ou cmdlets:• Utilisateur membre du groupe Administrateurs local• Fournir des credentials Administrateur • Accéder à la configuration de la session PowerShell• Sessions paramétrables

WinRM et la sécurité

Page 17: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

• WinRM Quickconfig

Installation de WinRM

Page 18: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

• Enable PSRemoting 

Installation de WinRM

Page 19: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

• GPO– Computer Configuration– Administrative Templates– Windows Components– Windows Remote Management– WinRM Service

 

Installation de WinRM

Page 20: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

• Vérifier la connexion localement:– winrm quickconfig

– Enter-PSSession -ComputerName localhost

Vérifications

Page 21: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

• Voir votre configuration :– winrm get winrm/config – winrm enumerate winrm/config/listener– ls WSMan:\localhost\Shell

Configuration 1/4

Page 22: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Configuration 2/4

Page 23: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Configuration 3/4

Page 24: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Configuration 4/4

Page 25: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Par défaut:• 30 sessions par utilisateur et par machine• 10 utilisateurs• 25 cmdlets simultanées, le reste en queue• 1024MB assigné par session

WinRM.. Des limitations….

Page 26: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Modifiables !

Page 27: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

LES SESSIONS

Page 28: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Fan-Out, 1-to-many• 1-to-1, SSH-style

Modèles de Remoting

Page 29: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Invoke-Command

Remoting 1-to-many

Page 30: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• On peut travailler avec la sortie de commande de quasiment la même manière que toute autre sortie de commande

Invoke-Command et les objets désérialisés

Page 31: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Les objets désérialisés que notre station reçoit sur le pipeline ne sont qu'un snapshot de l'objet original

Invoke-Command mais pas de méthodes

Page 32: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• La sérialisation et désérialisation des données a un coût très fort en terme de paquets envoyés sur le réseau

• Bonne pratique: utiliser Select-Object sur l'objet distant optimise l'envoi des données sur le réseau

Invoke-Command et Select-Object

Page 33: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Invoke-Command est sujet aux erreurs de frappe• On peut utiliser des scripts .ps1• Paramètre -FilePath

Invoke-Command sans erreur

Invoke-Command `-ComputerName vm2008R25,vm2008R26 `-FilePath C:\MyScript.ps1

Page 34: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Invoke-Command peut être utilisé avec le paramètre –AsJob– la commande est exécutée de façon asynchrone en arrière-plan– l’invite Windows PowerShell est immédiatement retourné

Le paramètre -AsJob

Page 35: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

Remoting SSH-style

Page 36: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

Exemple de session interactive temporaire

Page 37: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Les sessions temporaires ne sont pas efficientes– Overhead à l'initialization de chaque session– Overhead pour le tear-down de chaque session

• L’alternative: New-PSSession– pour démarrer une nouvelle session

persistante• Get-PSSession –ComputerName– pour voir une session existante

Sessions distantes persistantes

Page 38: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

La variable $Session• … ou comment faire du Invoke-Command sur une session persistante

Page 39: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

Rajouter une nouvelle session

Page 40: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Enter-PSSession accepte le paramètre -Session– La commande Exit-PSSession ne supprime pas

la session

Interagir avec une session persistante

Page 41: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Nouveauté dans Powershell 3.0• Connect-PSSession et Disconnect-PSSession• La reconnexion peut se faire:–du poste client où la session a été créée–à partir d'un autre poste (mais toujours

avec le même compte)–Powershell 3.0/4.0 installé des deux côtés

Sessions déconnectées

Page 42: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

Exemples de sessions déconnectées

Page 43: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Paramètre -InDisconnectedSession– depuis Powershell 3.0 permet à Invoke-Command de

profiter de la flexibilité et robustesse des sessions déconnectées

– la session est crée, la commande exécutée et la session est fermée  avant qu'une sortie soit produite

Invoke-Command et les sessions persistantes

Page 44: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Remove-PSSession

Détruire une session persistante

Page 45: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

• Pas de module sur votre station de travail ?

• Pas envie d'installer RSAT ?• Import-PSSession– importe des cmdlets à partir d'une session

PSSession d'un ordinateur local ou distant dans la session active.

Implicit Remoting

Page 46: Powershell et les techniques de remoting

#mstechdays Infrastructure, communication & collaboration

Exemple de Implicit Remoting

Page 47: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

COMMON INFORMATION MODEL

Page 48: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

• WMI intégré à tous les OS Microsoft.• WMI construit sur la base WBEM et CIM de la

DMTF• CIM permet une interface commune pour le

management:– OS Windows et Linux– Equipements réseaux– Solution de virtualisation

• PowerShell 1 et 2 -> WMI et accélérateurs• PowerShell 3 et 4 -> Module CIMCmdlets

Un peu d’histoire…

Page 49: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Les CMDLets CIM

Page 50: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Créer une session

Page 51: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Session avec options

Page 52: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Exécutions multiples

Page 53: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

Exécuter une méthode

Page 54: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

• Plus limité que WMI, actuellement:– Impossibilité de passer le paramètre credential sans créer

une session– Certaines Classes WMI sont manquantes– Impossibilité d’appeler des Objets/Méthodes .NET

Limitations

Page 55: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

DES QUESTIONS ?

Page 56: Powershell et les techniques de remoting

Pour aller plus loin…

ApprofondissezAgenda des séminaires techniques pour les IT Pros : http://aka.ms/itcamps-france

Agenda des séminaires fonctionnels pour les décideurs : http://aka.ms/TDI

Formez-vousFormations en ligne :http://aka.ms/MVA

Formation et certification gratuite:

Offre spéciale TechDays limitée aux 200 premières demandes, 1 pack par individu

Un pack digital offert intitulé “ Server Virtualization with Windows Server Hyper-V and System Center” comprenant le support de cours officiel Microsoft (MOC) au format digital (20409) et le coupon de certification (74-409).

A retirer exclusivement sur le stand de nos sponsors Learning Partner: Edugroupe (stand 30), Global Knowledge (stand 14), Ib (stand 74), SQLI (stand 97).

Évaluez des versions d'essai

#mstechdays Infrastructure, communication & collaboration

Microsoft System Center 2012

http://aka.ms/jeveuxmoncloudprive

http://aka.ms/free/trial

http://aka.ms/jeveuxwindows2012

Page 57: Powershell et les techniques de remoting

Infrastructure, communication & collaboration

#mstechdays

RESSOURCES• http://powershell-scripting.com – FR• http://lazywinadmin.com - US• http://learn-powershell.net – US• http://powershell.org – US• http://via-powershell.fr - FR• http://shellyourexperience.com - US• http://my-powershell.fr - FR• http://jdhitsolutions.com/blog -US • http://happysysadm.com – US• http://pwrshell.net – FR

Page 58: Powershell et les techniques de remoting

© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Digital is business