Powershell et les techniques de remoting

Preview:

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

Infrastructure, communication & collaboration

PowerShell et les techniques de remoting

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

@fdibot - @sysadm2010

#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 !

Infrastructure, communication & collaboration

#mstechdays

POWERSHELL REMOTING

#mstechdays Infrastructure, communication & collaboration

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

SOMMAIRE

Infrastructure, communication & collaboration

#mstechdays

UN PEU D’HISTOIRE

#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

#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

#mstechdays Infrastructure, communication & collaboration

Powershell Remoting, sauce 1.0…

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

#mstechdays Infrastructure, communication & collaboration

Le problème avec DCOM/RPC

Get-WMIObject

#mstechdays Infrastructure, communication & collaboration

• le parefeu gagne...

RPC/DCOM vs Parefeu

#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

Infrastructure, communication & collaboration

#mstechdays

WINRM

#mstechdays Infrastructure, communication & collaboration

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

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

WinRM

#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

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é

Infrastructure, communication & collaboration

#mstechdays

• WinRM Quickconfig

Installation de WinRM

Infrastructure, communication & collaboration

#mstechdays

• Enable PSRemoting 

Installation de WinRM

Infrastructure, communication & collaboration

#mstechdays

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

 

Installation de WinRM

Infrastructure, communication & collaboration

#mstechdays

• Vérifier la connexion localement:– winrm quickconfig

– Enter-PSSession -ComputerName localhost

Vérifications

Infrastructure, communication & collaboration

#mstechdays

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

Configuration 1/4

Infrastructure, communication & collaboration

#mstechdays

Configuration 2/4

Infrastructure, communication & collaboration

#mstechdays

Configuration 3/4

Infrastructure, communication & collaboration

#mstechdays

Configuration 4/4

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….

Infrastructure, communication & collaboration

#mstechdays

Modifiables !

Infrastructure, communication & collaboration

#mstechdays

LES SESSIONS

#mstechdays Infrastructure, communication & collaboration

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

Modèles de Remoting

#mstechdays Infrastructure, communication & collaboration

• Invoke-Command

Remoting 1-to-many

#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

#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

#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

#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

#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

#mstechdays Infrastructure, communication & collaboration

Remoting SSH-style

#mstechdays Infrastructure, communication & collaboration

Exemple de session interactive temporaire

#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

#mstechdays Infrastructure, communication & collaboration

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

#mstechdays Infrastructure, communication & collaboration

Rajouter une nouvelle session

#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

#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

#mstechdays Infrastructure, communication & collaboration

Exemples de sessions déconnectées

#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

#mstechdays Infrastructure, communication & collaboration

• Remove-PSSession

Détruire une session persistante

#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

#mstechdays Infrastructure, communication & collaboration

Exemple de Implicit Remoting

Infrastructure, communication & collaboration

#mstechdays

COMMON INFORMATION MODEL

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…

Infrastructure, communication & collaboration

#mstechdays

Les CMDLets CIM

Infrastructure, communication & collaboration

#mstechdays

Créer une session

Infrastructure, communication & collaboration

#mstechdays

Session avec options

Infrastructure, communication & collaboration

#mstechdays

Exécutions multiples

Infrastructure, communication & collaboration

#mstechdays

Exécuter une méthode

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

Infrastructure, communication & collaboration

#mstechdays

DES QUESTIONS ?

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

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

© 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

Recommended