Getting Started With PowerShell Scripting

  • 4,487 views
Uploaded on

This slide was used at @PSBUG or PowerShell Bangalore User Group UG meet. This shows some fundamentals about getting started with PowerShell scripting

This slide was used at @PSBUG or PowerShell Bangalore User Group UG meet. This shows some fundamentals about getting started with PowerShell scripting

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,487
On Slideshare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
269
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Getting started with PowerShell Scripting
    Ravikanth C
  • 2. A lead engineer at Dell
    SharePoint professional by day and PowerShell scripter at night
    Blog at http://www.ravichaganti.com/blog
    Developer of
    PSCodePlex
    PSRemoteFileExplorer
    Remote File Explorer PowerPack
    BITS File Transfer PowerPack
    Author of
    Free eBook - Layman’s guide to PowerShell 2.0 remoting (Coming soon)
    About me
  • 3. What is PowerShell?
    Getting started
    Using PowerShell
    Getting Help
    Tools for the job
    Learning resources
    Q & A
    Agenda
  • 4. Remote file explorer -> 698 lines of PowerShell
    This is just one example..!
    Show me the Power first.!
  • 5. The best shell scripting environment for Windows
    A new scripting language
    Replacement for a weak Windows command-line
    Default management / automation platform for all Microsoft products going forward
    Object based
    Built on top of .NET type system
    Everything is an object
    What is PowerShell?
  • 6. PowerShell is in version 2.0
    Default on Windows 7 and Windows Server 2008
    Part of Windows management framework download for Windows Server 2008, Vista, XP and Windows 2003
    http://support.microsoft.com/kb/968929
    Requires .NET 2.0 SP1 or later
    Getting started
  • 7. Console history, Intellisense for cmdlets, variables and parameters
    Using PowerShell: Console
  • 8. Using PowerShell: ISE
  • 9. Using PowerShell: Cmdlets
    • Pronounced as command-let
    • 10. A lightweight command
    • 11. an instance of .NET framework classes
    • 12. Use verb-noun pairs
    • 13. Get-Verb to list all approved verbs
  • Not case-sensitive
    Default value is $null
    Cmdlets to manage variables
    Clear-Variable
    Get-Variable
    New-Variable
    Remove-Variable
    Set-Variable
    Using PowerShell: Variables
  • 14. 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
    Using PowerShell: Variables
  • 15. 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
    Using PowerShell: Aliases
  • 16. 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++ }
    Using PowerShell: Conditional & Looping
  • 17. Comparison operators
    -ne, -eq, -lt, -gt, -ge, -le, -like, -notlike, -contains, -notcontains, -match, -notmatch
    Logical operators
    -or, -and, -xor, -not, !
    Arithmetic operators
    Assignment operators
    Using PowerShell: Operators
  • 18. Arrays
    Collection of objects of the same type
    $a = @( )
    $a = “PowerShell”,”VBScript”
    Hash Tables
    Collection of key value pairs
    $ hash = @{ }
    $a = {“Name”=“PowerShell”; “IsHot”=$true}
    Using PowerShell: Arrays & Hash Tables
  • 19. 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*
  • 20. In PowerShell, there will be more than one way to do the same thing. For example
    [System.Diagnostics.Process]::GetProcesses()
    Get-Process
    Understand execution policies
    Use PowerShell profiles
    Best practices
  • 21. PowerShell Console
    PowerShell ISE
    PowerGUI AdminConsole
    PowerGUI ScriptEditor
    PowerWF
    PowerShell Plus
    Tools for the job
  • 22. Getting started guide
    PowerShell Learning center
    Free PowerShell eBook
    The scripting Guys blog
    PowerScripting Podcast
    @PSBUG on Twitter
    Learning resources