Learning PowerShell

royalroyal Member Posts: 3,353
I've seen several people ask for the best way to learn PowerShell. As a person with no previous scripting knowledge, I have been learning PowerShell and have already created several pretty lengthy scripts. So are you interested in learning? If so, here's what I did and it may help you out in the future.

Go through this guy's tutorials before anything else:
http://www.powershellpro.com/

Then go through this book:
http://www.amazon.com/Microsoft-PowerShell-Programming-Absolute-Beginner/dp/1598633546/ref=sr_1_1?ie=UTF8&s=books&qid=1227659316&sr=8-1

Then go through about 50-60% of this book (the rest is too much for an admin and more for devs):
http://www.amazon.com/Windows-PowerShell-Action-Bruce-Payette/dp/1932394907/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1227659351&sr=8-1

At the time of this posting, I am going through the PowerShell Cookbook Some of the stuff is over my head but it has excellent snippets that you can use as well as excellent Appendixes which list out common COM Objects you would use as an Administrator, common type classes, etc...
http://www.amazon.com/Windows-PowerShell-Cookbook-Exchange-2007/dp/0596528493/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1227659542&sr=8-1

After I'm finished with the Cookbook I will be going through this AD PowerShell book:
http://www.sapienpress.com/ad.asp

PowerShell Technology Center which includes a link to the Scripting Repository Center. Ed Wilson just became the new Scripting Guy and will be focusing on adding lots of PowerShell content to the site.
http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Don't forget to read these PowerShell tips:
http://www.microsoft.com/technet/scriptcenter/resources/pstips/archive.mspx

PowerGUI (Free Script Editor):
http://powergui.org/index.jspa

Primalscript (Not-Free Script Editor)... One thing to note about Primalscript is that 2009 is coming out in early 2009 and will have lots of PowerShell stuff integrated. I'll be purchasing this when it's released.
http://www.primalscript.com/

There's quite a bit of other stuff out there but you'll learn the good community sites as you learn PowerShell and need to look stuff up. Hope this helps!
“For success, attitude is equally as important as ability.” - Harry F. Banks

Comments

  • jbaellojbaello Member Posts: 1,192
    So awesome Royal thanks...
  • dynamikdynamik Banned Posts: 12,314 ■■■■■■■■□□
    Nice list. That cookbook is pretty sweet, isn't it? Simply doing a recipe or two a day really increases your exposure to different scenarios and helps you learn the language. Don't you also have a PS book geared towards Exchange? I thought I saw you mention that in another thread.
  • royalroyal Member Posts: 3,353
    dynamik wrote:
    Nice list. That cookbook is pretty sweet, isn't it? Simply doing a recipe or two a day really increases your exposure to different scenarios and helps you learn the language. Don't you also have a PS book geared towards Exchange? I thought I saw you mention that in another thread.

    I do. The reason I didn't link it is it's more geared towards just the Exchange Management Shell and not scripting itself. So it's more for learning Exchange commands rather than scripting. But of course you have to know what the commands are in order to script for it, but it still doesn't teach you scripting.

    And yes, the PowerShell Cookbook is very good. I really like the Appendices.

    I was scripting something a few days ago on how to take a list of users from a CSV file (their Display Name) and get their DN but was getting frustrated at something so I did it differently. I read a snippet today and realized why it didn't work.
    ## Modify the file location
    $file = "C:\FindDN.csv"

    # Do not Modify the below
    $erroractionpreference = "SilentlyContinue"

    function Get-DistinguishedName ($displayName) {
    $ads = New-Object System.DirectoryServices.DirectorySearcher([ADSI]'')
    $ads.filter = "(&(objectClass=Person)(displayName=$displayName))"
    $s = $ads.FindOne()
    return $s.GetDirectoryEntry().DistinguishedName
    }

    if ((Test-Path $file) -eq "True") { $users = Import-CSV $file }
    else { Write-Warning "$file does not exist" ; exit }

    Function Get-Data {
    foreach ($user in $users) {
    $dn = Get-DistinguishedName $user."DisplayName"
    $obj = New-Object PSObject
    $obj | Add-Member NoteProperty "Display Name" $user."DisplayName"
    $obj | Add-Member NoteProperty "Distinguished Name" $dn
    $obj
    }
    }
    Get-Data

    One cool thing I always do with output is create the custom PSObject and add data to it. The reason I do this is instead of returning output directly to Format-Table or Format-List, the PSobject allows you to display output to the console but still choose if you want to FT, FL, Export to File, CSV, etc... It really gives you a lot of flexibility on how you want your code outputted.
    “For success, attitude is equally as important as ability.” - Harry F. Banks
  • HeroPsychoHeroPsycho Inactive Imported Users Posts: 1,940
    royal wrote:
    I was scripting something a few days ago on how to take a list of users from a CSV file (their Display Name) and get their DN but was getting frustrated at something so I did it differently.

    Let cmdlets do the work for you. Quest AD cmdlets can do this out of the box.
    Good luck to all!
  • astorrsastorrs Member Posts: 3,139 ■■■■■■□□□□
    HeroPsycho wrote:
    Let cmdlets do the work for you. Quest AD cmdlets can do this out of the box.
    Yeah the Quest AD cmdlets are awesome; they can work in both a standalone AD environment or in one managed by ActiveRoles server (common in large environments).

    http://www.quest.com/powershell/activeroles-server.aspx
  • royalroyal Member Posts: 3,353
    HeroPsycho wrote:
    royal wrote:
    I was scripting something a few days ago on how to take a list of users from a CSV file (their Display Name) and get their DN but was getting frustrated at something so I did it differently.

    Let cmdlets do the work for you. Quest AD cmdlets can do this out of the box.

    I'd rather do it the way I did it learn how to script as Quest AD cmdlets most likely won't even be used in Server 2008 R2 as all the cmdlets will be built into Server 2008 R2 and more.
    “For success, attitude is equally as important as ability.” - Harry F. Banks
  • HeroPsychoHeroPsycho Inactive Imported Users Posts: 1,940
    That's when I'd use the included Windows AD cmdlets for that.

    There are numerous ways to skin a cat, and to each his own. I just want to skin it faster. :D
    Good luck to all!
  • royalroyal Member Posts: 3,353
    I hear you, but I'd rather do it the longer way and get more long-term benefit from knowing how to become a better/stronger scripter. Not saying you're way is wrong, I just prefer to go about it a different way.
    “For success, attitude is equally as important as ability.” - Harry F. Banks
  • HeroPsychoHeroPsycho Inactive Imported Users Posts: 1,940
    I freely admit I'm lazy. icon_lol.gif
    Good luck to all!
Sign In or Register to comment.