Powershell

Preview:

DESCRIPTION

 

Citation preview

Windows PowerShell une nouvelle approche de

l’administration des environnements Windows

ObjectifPour les néophiques : découvrir Windows

PowerShellPour les experts : comment étendre Windows

PowershellPas trop de blabla, des démonstrations !!

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

AgendaDécouverte de Windows PowerShell

Windows PowerShell et l’administration

Etendre Windows PowerShell

Découverte de 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.

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

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

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

ou MUI (KB926141)

<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

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 ?

5 categories de commandes

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

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

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

Les Types

PowerShell et les nombres

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

Les opérateurs PowerShell

Plus de détails : help about*operator*

Les instructions de contrôle de flux

Fournisseurs et magasins de données

PowerShell et les fichiers

PowerShell et le texte

Les ordres de formatage

PowerShell et XML

PowerShell et l’accès au système

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

Accès universel !

ADSI &ADO .Net

webserviceTXTTXT

Services &Processus

WMI

COM

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é

Windows PowerShell et l’administration

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

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

Au cœur des solutions d’entreprise

EtendreWindows PowerShell

Etendre Windows PowerShellComment fonctionne Windows PowerShell

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

Functions/Filters/ScriptsCmdletsProvidersHosts

Etendre 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

Questions?

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

www.PowerShell-Scripting.comEntrez dans la communauté

francophone

Profitez d’un partage de connaissances autour de PowerShell

Ressources

© 2007 Microsoft France

Votre potentiel, notre passion TM

Reference Slides

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

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'"

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

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

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

Recommended