49
Windows PowerShell une nouvelle approche de l’administration des environnements Windows

Powershell

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Powershell

Windows PowerShell une nouvelle approche de

l’administration des environnements Windows

Page 2: Powershell

ObjectifPour les néophiques : découvrir Windows

PowerShellPour les experts : comment étendre Windows

PowershellPas trop de blabla, des démonstrations !!

Page 3: Powershell

Windows PowerShellWindows PowerShell est une invite de

commande (shell) interactive et un environnement de scripts offrant une manière de traiter des tâches orientée commandes.

Les concepteurs ont suivi différentes approches afin que PowerShell soit :aussi interactif et composable que KSH ou BASH,aussi programmable que PERL ou RUBY,aussi orienté-production que VMS DCL ou AS400 CL.permettre l’accès aux sources de données aussi

facilement que l’accès au système de fichiers

Page 4: Powershell

AgendaDécouverte de Windows PowerShell

Windows PowerShell et l’administration

Etendre Windows PowerShell

Page 5: Powershell

Découverte de PowerShell

Page 6: Powershell

Mieux comprendre la structure et les bénéfices de PowerShell !

« J’ai refait tous les calculs, ils confirment l’opinion des spécialistes : mon idée est irréalisable. Il ne me reste plus qu’une seule chose à faire : la réaliser » Pierre-Georges Latécoère.

Page 7: Powershell

Découverte de PowerShell

1. Les basesLe modèle des commandesQue manipule-t-on ? Expressions, Variables, TypesLe pipeline & les filtres

2. Constructions du langageOpérateursTests & boucles

3. Intégration avec le systèmeLecteurs étendusWMICOM

Page 8: Powershell

Configuration de PowerShell Version 1.0 Pré-requis : Framework .Net 2.0 Disponible pour:

Windows ServerCode Name Longhorn

• Une « feature » à installer• Pas installée par défaut• Pas disponible avec « Server Core »

•x86•x64•IA64

Windows Server 2003 SP1

• Une mise à jour système entre le SP1 et le SP2 (KB926139, 140, 141)• A télécharger

•x86•x64•IA64

Windows Vista • Une mise à jour (KB928439)• A télécharger

•x86•x64

Windows XP SP2

• Une mise à jour système (KB926139, 140, 141)• A télécharger

•x86•x64

http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx

Page 9: Powershell

Multi-langues Version anglaise (KB926139) Ou version localisée en 10 autres langues (KB926140) :

ou MUI (KB926141)

Page 10: Powershell

<verb>-<nom>

Homogénéité & Cohérence

Get-Command sur le modèle :

avec un certain nombre de paramètres omniprésents :

Plus de détails : help about-parameter

help about_commonparameters

Page 11: Powershell

Les 4 commandes de découverte

1. Get-Command informations de base sur les commandes

2. Get-help aide de base (utiliser –full)

3. Get-member informations sur les objets

4. Get-PSDrive informations sur les lecteurs étendus

Get-commandGet-helpGet-memberGet-psdrive

parmi 129 commandes intégrées ou “cmdlets” commandettes ?

Page 12: Powershell

5 categories de commandes

Plus de détails : get-command * | group commandtype

Page 13: Powershell

Tout est objet !(date).adddays(100)

Page 14: Powershell

L’accès aux objets est uniformisé !

.Net Object Adapter

WMI Object Adapter

COM Object Adapter

Other Adapters :ADSI , ADO…

Custom Object Adapter

.Net Object

WMI ObjectScript PowerShell accédant à un objet

COM Object

Page 15: Powershell

Les Types

Page 16: Powershell

PowerShell et les nombres

Plus de détails : [math] | get-member -static

Page 17: Powershell

Les opérateurs PowerShell

Plus de détails : help about*operator*

Page 18: Powershell

Les instructions de contrôle de flux

Page 19: Powershell

Fournisseurs et magasins de données

Page 20: Powershell

PowerShell et les fichiers

Page 21: Powershell

PowerShell et le texte

Page 22: Powershell

Les ordres de formatage

Page 23: Powershell

PowerShell et XML

Page 24: Powershell

PowerShell et l’accès au système

Page 25: Powershell

Stratégie d’éxécution Contrôle ce qui peut être exécuté Get-ExecutionPolicy

Set-ExecutionPolicy

Set-ExecutionPolicy UnRestricted

Plus de détails : help about_signing

Page 26: Powershell

Accès universel !

ADSI &ADO .Net

webserviceTXTTXT

Services &Processus

WMI

COM

Page 27: Powershell

Que faut-il retenir ?Une syntaxe homogène : verbe-nomLes 4 commandes de base :

Get-command, get-help, get-member, get-psdrive

Tout est objet !Le pipeline aussi !

Interactions avec le système via :Text & XMLCOM & .NetWMI et EventLog

Sécurisé

Page 28: Powershell

Windows PowerShell et l’administration

Page 29: Powershell

L’administration Outils d’administration « graphique »Outils en ligne de commande natifs (cmd, exe,

etc…)Scripting Windows Automatiser les tâches

d'administrationVBScript, WSH, WMI, ADSI, CDO et les objets COM

Page 30: Powershell

Windows PowerShell et l’administration

L'objectif : Améliorer et faciliter le contrôle administratif sur les systèmes, que ce soit de manière interactive ou par le biais de scripts.Gestion des processus locaux Gestion de services locauxCollecte d'informations sur des ordinateursUtilisation d'installations logicielles Changement d'état de l'ordinateur : verrouillage,

fermeture de session, arrêt en cours et redémarrage Utilisation d'imprimantes Tâches de gestion de réseau Utilisation des fichiers et dossiersUtilisation du registre

Page 31: Powershell

Au cœur des solutions d’entreprise

Page 32: Powershell
Page 33: Powershell

EtendreWindows PowerShell

Page 34: Powershell

Etendre Windows PowerShellComment fonctionne Windows PowerShell

Les différentes manières d’étendre Windows PowerShell

Page 35: Powershell
Page 36: Powershell

Functions/Filters/ScriptsCmdletsProvidersHosts

Page 37: Powershell

Etendre PowerShell

Page 38: Powershell

Communauté Française : http://www.powershell-scripting.com/

Newsgroup: Microsoft.Public.Windows.PowerShellTeam blog: http://blogs.msdn.com/PowerShell/Channel 9 tag: http://channel9.msdn.com/tags/PowerShellOMark van Orsouw’s blog: http://ThePowerShellGuy.ComWiki: http://channel9.msdn.com/wiki/default.aspx/Channel9.WindowsPowerShellWikiScript Center:

http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspxManning Press book by Bruce Payette: PowerShell in Action

http://manning.com/powershell/ O’Reilly book – Monad: Introducing the MSH Command Shell and Language

http://www.oreilly.com/catalog/msh/Sapien Press book by Don Jones: PowerShell

http://www.sapienpress.com/MshAnalyzer tool

http://www.karlprosser.com/coder/?cat=8

Page 39: Powershell

Questions?

Page 40: Powershell

RessourcesRessourcesTechnical Chats and Webcastshttp://www.microsoft.com/communities/chats/default.mspx http://www.microsoft.com/usa/webcasts/default.asp

Microsoft Learning and Certificationhttp://www.microsoft.com/learning/default.mspx

MSDN & TechNet http://microsoft.com/msdnhttp://microsoft.com/technet

Virtual Labshttp://www.microsoft.com/technet/traincert/virtuallab/rms.mspx

Newsgroupshttp://communities2.microsoft.com/communities/newsgroups/en-us/default.aspx

Technical Community Siteshttp://www.microsoft.com/communities/default.mspx

User Groupshttp://www.microsoft.com/communities/usergroups/default.mspx

Page 41: Powershell

www.PowerShell-Scripting.comEntrez dans la communauté

francophone

Profitez d’un partage de connaissances autour de PowerShell

Page 42: Powershell

Ressources

Page 43: Powershell

© 2007 Microsoft France

Votre potentiel, notre passion TM

Page 44: Powershell

Reference Slides

Page 45: Powershell

Access existing instrumentationBind to COM objects

$fso = New-Object -ComObject Scripting.FileSystemObject

$m = [System.Runtime.InteropServices.Marshal]

$word = $m::GetActiveObject("Word.Application")

Invoke methods/access properties$fso.GetDrive(“C:”)

$fso.VolumeName = “System Drive”

Understand/extend instrumentationExtend and discover properties/methods

Update-TypeData Office.Word.Types.ps1xml

$fso | Get-Member

Manipulate and format resultsDefine and import custom formating

Update-FormatData Office.Word.Format.ps1xml

$word.RecentFiles | Sort name | Format-Table

Allows more simpler/more powerful COM scripts Allows more simpler/more powerful COM scripts because of utilities and formattingbecause of utilities and formatting

Page 46: Powershell

PowerShell provides native WMI supportGet-WmiObject

Allows for inspection of WMI namespaceGet-WmiObject –list [-Namespace xx]Get-WmiObject –Class xx –Namespace xx –Property xxx – Filter xxx –ComputerName xxx –Credential xxx

Native language support[WMI] “\\JPSDESK10\root\cimv2:Win32_Process.Handle="0“[WMICLASS] "ROOT\cimv2:WIN32_PROCESS"[WMISEARCHER]"select * from Win32_process WHERE Name = 'calc.exe'"

Page 47: Powershell

PowerShell provides native access to any .NET classCreate any object

[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")$d = New-Object System.DateTime 2006,12,25

Access Properties/Invoke Methods$d.DayOfWeek$d.AddDays(-30)

Access Statics[DateTime]::Now[DateTime]::IsLeapYear(2006)

Allows admins to easily Allows admins to easily access and leverage a huge access and leverage a huge API set because of API set because of scriptability, utilities and scriptability, utilities and formattingformatting

Page 48: Powershell

PowerShell provides native XML supportNative datatype

$x=[xml]"<a><b><c>TEST</c></b></a>“$b =[xml](type c:\i386\mssecure.xml)

Native syntax to access “data” view of properties

$b.BulletinDataStore.Bulletins.Bulletin[0]

Access to XML methods $b.BulletinDataStore.SelectNodes(“//Patch”)

XML properties available through PSBase property

$b.BulletinDataStore.PSBase.innerXml

Page 49: Powershell

Invoke existing tools Existing command run directly after variables are expanded

Harvest data from existing toolsParse output into variables using text utilities.

Pipe data to SELECT and use –FIRST and –LAST

Select-String <REGEX> <Path>

Dir | Select-String <REGEX>

[DateTime]”12/25/2006 7:00”

([DateTime]”12/25/2006 7:00”).AddDays(-30)

Use functions/scripts to wrap the commands and convert output to objects or provide standard syntax

Safely process textUse CLR types via Windows PowerShell to safely parse text

[URI]” http://blogs.msdn.com/powershell/archive/2006/04/25/583234.aspx”

Allows admins to get 2-10x more power out of Allows admins to get 2-10x more power out of existing commands because of scriptabilityexisting commands because of scriptability