Windows PowerShell  The Next Generation Command Line Scripting Phan Quoc Hien  B110077
Agenda Introduction What is Windows PowerShell? Using PowerShell How can I script with Windows PowerShell? PowerShell and .net How .net developers will benefit from PowerShell
Introduction What is PowerShell?
What is PowerShell Revolutionary new interactive shell and scripting language Based on .NET New set of built-in tools (+120) Can continue to use current tools Can continue to use current automation (COM) Allows access to data stores as  easy  to access  as file systems
Why? Try things out in an interactive shell Stitch things together with utilities Put the results in a script file  Generalize Clean it up    production-quality Be more Productive Secure by default
Where ? Supported on Windows XP and above Microsoft Products Exchange 2007 System Center (Family) 2007 New Management Architecture based on PowerShell Windows Server 2008 None Microsoft Products IBM WebSphere MQ 6 VMWare InfrastructureToolkit
Using PowerShell
How to start? PowerShell is a free download from Microsoft Separate download for each windows version
The basics Syntax:  verb-noun  –parameter   arguments Always singular, parameters starts with “ - ” Examples: > Get-Process –name ie* > Get-Process ie* > Get-Service > Read-Host “Please Enter a number”
The basics (cont’d) You can alias Set-Alias gps Get-Process Parameters can be positional gps –ProcessName notepad gps notepad Many parameters can be wildcarded gps note* Partial parameter names allowed Gps –p notepad
Variables Not case-sensitive Default value is $null Cmdlets to manage variables Clear-Variable Get-Variable New-Variable Remove-Variable Set-Variable
Variables (cont’d) Types User created variables Automatic variables Created by PowerShell to maintain its state Cannot be modified Examples: $PSHome, $$, $^, $?, etc Preference variables Created by PowerShell to store user preferences Can be modified Examples: $MaximumHistoryCount, etc
Aliases Alternate names for cmdlets Cmdlets to manage aliases Export-Alias Get-Alias Import-Alias New-Alias Set-Alias Cannot take parameters Workaround: put the statement in a script and alias to that Example: Dir, ls, gcm, gci, etc
Conditional & Looping Conditional statements If Switch l.ooping For For ($i=0;$i –le 10;$i++)  {Write-Host $i} Foreach Used on a collection of items Foreach ($name in $namesArray) { Write-Host $name } Do Do { Write-Host $i; $i++ } while ($i –le 10) Do { Write-Host $i;$i++} Until ($i –lt 10) While While ($i –le 10) { Write-Host $i;$i++ }
Operators Comparison operators -ne, -eq, -lt, -gt, -ge, -le, -like, -notlike, -contains, -notcontains, -match, -notmatch Logical operators -or, -and, -xor, -not, ! Arithmetic operators Assignment operators
Getting Help Get-Command Gets a list of all commands  Get-Help Shows help for a given cmdlet Get-Member Gets members of an object Get-PSDrive Shows information stores in PowerShell About_Topics Get-Help about*
Trusting Operations Commands with side-effects support: Whatif Stop-Service win* –WhatIf Confirm Stop-process S* -Confirm Verbose
Security is key for PowerShell By default, only interactive usage allowed If you want to use scripting, you need to change the  ExecutionPolicy Get-ExecutionPolicy / Set-ExecutionPolicy PS1 files opened with Notepad by design
Finding Data in Data Stores Data stores surfaced as “Drives” Filesystem, Registry, Alias, Certs, Env, Functions, Variables, etc. > Get-PSDrive > dir  HKLM:\SOFTWARE\Microsoft Rich common semantics > Dir  \logs –Include *.txt –Exclude A* -Recurse Tab-Completion in all Drives > Dir HKLM:\So<TAB>\Mi<TAB> => HLKM:\Software\Microsoft Demo 1 : File System Navigation Demo 2 : Registry Navigation Demo 3 : Environment Variables Navigation
 
Out-Thankyou PS C:\> Thank you for your time and attention. Good luck in your PowerShell Adventures! PS C:\>

NIIT ISAS Q5 Report - Windows PowerShell

  • 1.
    Windows PowerShell The Next Generation Command Line Scripting Phan Quoc Hien B110077
  • 2.
    Agenda Introduction Whatis Windows PowerShell? Using PowerShell How can I script with Windows PowerShell? PowerShell and .net How .net developers will benefit from PowerShell
  • 3.
  • 4.
    What is PowerShellRevolutionary new interactive shell and scripting language Based on .NET New set of built-in tools (+120) Can continue to use current tools Can continue to use current automation (COM) Allows access to data stores as easy to access as file systems
  • 5.
    Why? Try thingsout in an interactive shell Stitch things together with utilities Put the results in a script file Generalize Clean it up  production-quality Be more Productive Secure by default
  • 6.
    Where ? Supportedon Windows XP and above Microsoft Products Exchange 2007 System Center (Family) 2007 New Management Architecture based on PowerShell Windows Server 2008 None Microsoft Products IBM WebSphere MQ 6 VMWare InfrastructureToolkit
  • 7.
  • 8.
    How to start?PowerShell is a free download from Microsoft Separate download for each windows version
  • 9.
    The basics Syntax: verb-noun –parameter arguments Always singular, parameters starts with “ - ” Examples: > Get-Process –name ie* > Get-Process ie* > Get-Service > Read-Host “Please Enter a number”
  • 10.
    The basics (cont’d)You can alias Set-Alias gps Get-Process Parameters can be positional gps –ProcessName notepad gps notepad Many parameters can be wildcarded gps note* Partial parameter names allowed Gps –p notepad
  • 11.
    Variables Not case-sensitiveDefault value is $null Cmdlets to manage variables Clear-Variable Get-Variable New-Variable Remove-Variable Set-Variable
  • 12.
    Variables (cont’d) TypesUser created variables Automatic variables Created by PowerShell to maintain its state Cannot be modified Examples: $PSHome, $$, $^, $?, etc Preference variables Created by PowerShell to store user preferences Can be modified Examples: $MaximumHistoryCount, etc
  • 13.
    Aliases Alternate namesfor cmdlets Cmdlets to manage aliases Export-Alias Get-Alias Import-Alias New-Alias Set-Alias Cannot take parameters Workaround: put the statement in a script and alias to that Example: Dir, ls, gcm, gci, etc
  • 14.
    Conditional & LoopingConditional statements If Switch l.ooping For For ($i=0;$i –le 10;$i++) {Write-Host $i} Foreach Used on a collection of items Foreach ($name in $namesArray) { Write-Host $name } Do Do { Write-Host $i; $i++ } while ($i –le 10) Do { Write-Host $i;$i++} Until ($i –lt 10) While While ($i –le 10) { Write-Host $i;$i++ }
  • 15.
    Operators Comparison operators-ne, -eq, -lt, -gt, -ge, -le, -like, -notlike, -contains, -notcontains, -match, -notmatch Logical operators -or, -and, -xor, -not, ! Arithmetic operators Assignment operators
  • 16.
    Getting Help Get-CommandGets a list of all commands Get-Help Shows help for a given cmdlet Get-Member Gets members of an object Get-PSDrive Shows information stores in PowerShell About_Topics Get-Help about*
  • 17.
    Trusting Operations Commandswith side-effects support: Whatif Stop-Service win* –WhatIf Confirm Stop-process S* -Confirm Verbose
  • 18.
    Security is keyfor PowerShell By default, only interactive usage allowed If you want to use scripting, you need to change the ExecutionPolicy Get-ExecutionPolicy / Set-ExecutionPolicy PS1 files opened with Notepad by design
  • 19.
    Finding Data inData Stores Data stores surfaced as “Drives” Filesystem, Registry, Alias, Certs, Env, Functions, Variables, etc. > Get-PSDrive > dir HKLM:\SOFTWARE\Microsoft Rich common semantics > Dir \logs –Include *.txt –Exclude A* -Recurse Tab-Completion in all Drives > Dir HKLM:\So<TAB>\Mi<TAB> => HLKM:\Software\Microsoft Demo 1 : File System Navigation Demo 2 : Registry Navigation Demo 3 : Environment Variables Navigation
  • 20.
  • 21.
    Out-Thankyou PS C:\>Thank you for your time and attention. Good luck in your PowerShell Adventures! PS C:\>

Editor's Notes

  • #2 INF210
  • #3 10/02/11 11:24 © 2006 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.
  • #5 10/02/11 11:24 MICROSOFT CONFIDENTIAL © 2006 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.
  • #6 10/02/11 11:24 © 2006 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.
  • #9 Start NOW !
  • #11 10/02/11 11:24 © 2006 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.
  • #18 10/02/11 11:24 © 2006 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.
  • #20 10/02/11 11:24 © 2006 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. Demo Get-PSDrive Show navigation in File System and Registry