My PowerShell training. :)

Last week I had finally chance to share what I know about PowerShell with others in my company. It was real ‘crush-course’ – 2 hours of speaking, without any breaks, and I still have not mentioned all goodies PowerShell has for any IT Pro within range. 😉 I’ve used some slides from PowerShell’s Almighty’s presentation from TechEd Berlin: great to show objects and pipelines. I had number of demos to show how it works in action (ISE is really great for demos!), prepared homework so that guys could give it a try and jump on this horse. I tried to focus on stuff that may be handy for people on a position like mine, but had to start with some basics and I guess it was really hard (no scripters, very little cmdline experience, no idea about object programming, 0 experience with WMI). My manager also wanted to attend and I’m happy that he really enjoyed the training and already played with PowerShell (did first task from homework 😀 )

So what topics did I covered? Basics (what it is, how to install it, use it, few words about hosts, how you can jump from cmd/ bash, few words about objects, pipeline, variables, arrays), 3 cmdlets to start with (Get-Command, Get-Help, Get-Member) and technologies: WMI and AD (Quest). Later I mentioned some things that one can do to avoid problems (-WhatIf, –Confirm, building command one pipe at the time). When I finished and asked for questions I got silence instead of a reply. Than my manager just said that it’s hard to ask questions now, because they need to consume this piece of data first. 😀 So I just added Christmas Tree from Jaykul and show them in action script to prepare weekly report (with data taken from AD, imported to Excel, with pivot table, chart and conditional formatting). Just to let them know – nothing is preventing you from starting with Get-Process, and finally end up with Get-JobDone. 😉

One sample from demos:

PowerShell, using GeSHi
  1. # We can query for some crazy things…
  2. GetQADUser FirstName Anna
  3. # LDAP paths are not friendly :/
  4. GetQADUser SearchRoot ‘OU=STO,DC=EU,DC=PXL,DC=INT’ Enabled
  5. GetQADUser SearchRoot ‘OU=STO,DC=EU,DC=PXL,DC=INT’ Enabled | select Name, PasswordExpires
  6. # So we store them in variable and forget this crazy syntax. 😉
  8. # Step-by-step in our time machine… 🙂
  9. $Today = Get-Date
  10. $MonthAgo = $Today.AddDays(30)
  11. # let’s take a look on my PC. SP3 there already…?
  12. GetQADComputer -Name WAR000260 | Select Name, OSServicePack
  13. # How are we doing in STO with that?
  14. GetQADComputer LastChangedAfter $MonthAgo SearchRoot $ad_sto OSName ‘Windows XP Professional’ | select name, OsServicePack, Description
  15. # Wonder if there are some people who have SP4 already. 😉
  16. GetQADComputer OSServicePack ‘Service Pack 4’ SizeLimit 0 LastChangedAfter $MonthAgo | select Name, OSName, OSServicePack
  17. # Now: volounteer to see all properties that we get by default… 🙂
  18. ‘EldereE’, ‘BaumgaG’, ‘PobereA’, ‘MoyseyS’, ‘RadzkiM’, ‘GerasiD’ | GetRandom | GetQADUser | fl *
  19. # And something even more intense: full set of AD properties…
  20. GetQADUser BielawB IncludeAllProperties | Format-List *
  21. # Cost center? Title? Anyone? 🙂 As Html? With Css?
  22. GetQADUser SearchRoot $AD_STO IncludedProperties division | select Name, Title, division | ConvertTo-Html -Head $MyTableCss | Out-File Report.htm
  23. # So now let us send this report to ourselfs, originitated from some fellow from MS. 😉
  24. $To = ‘EldereE’, ‘BaumgaG’, ‘PobereA’, ‘MoyseyS’, ‘RadzkiM’, ‘GerasiD’, ‘KroeseM’ | GetQADUser | select -ExpandProperty email
  25. SendMailMessage From ‘’ To $To Subject ‘TADAM!’ SmtpServer ‘’ BodyAsHtml -Body (Get-Content .\Report.htm | Out-String)

I think it was really worth it… I was tired like hell after, but you know – PowerShell is a joy you want to share. It’s a key to crazy stuff that you would like others to discover. I’m happy because I already got a list of another 15 people that would like to attend to this training. And this time I won’t have to hurry so much. Last time I had a group of people that are alone on site and need to do everything by themselves. What it means? They had no time to waste. They could expect storm any second. 😉 And when you have to choose between some fancy training and fire at your door, what would you choose to take care of first? So homework I’ve created has no deadline:

PowerShell, using GeSHi
  1. # 1. Try to check in registry what is your PC name in NDS using PowerShell registry provider
  2. # hint: info is stored in HKLM\Software\Novell\Workstation Mangager\Identification…
  3. Get-ItemProperty -?
  4. # 2. Check your System eventlog to see what is the Source of most of Errors
  5. Get-EventLog -?
  6. Get-Help Get-EventLog -Parameter EntryType
  7. Get-EventLog -LogName System | select -First 1 | Get-Member Source
  8. Group-Object -?
  9. Get-Help Group-Object -Parameter Property
  10. # 3. Get info (formated in table) about 5 computers: computer Manufacturer, Model, TotalPhysicalMemory, UserName and format it as a table
  11. # hint: all info available in win32_ComputerSystem class in WMI
  12. Get-WmiObject Win32_ComputerSystem | select Caption, Manufacturer, Model, TotalPhysicalMemory, UserName
  13. # 4. Get names of 5 users that will have their password expire soonest in your location, use only -Enabled users for that report.
  14. Get-Help Select-Object -Parameter First
  15. Sort-Object -?
  16. # 4a. Make it HTML and sent it to me. 😉
  17. SendMailMessage -?
  18. # 5. Save all files in your roor directory in $array and display first and last element in this array.
  19. Get-ChildItem c: | Get-Member PsIsContainer
  20. Get-Help Where-Object -Examples
  21. # Spoiler. 😉
  22. $MyArray = ‘first’,‘second’,‘third’,‘last’
  23. $MyArray[0]
  24. $MyArray[1]

Man, I really can’t wait to next training session. I guess it might be even better: I would expect more scripters/ quasi-programmers/ cli-users this time. And I probably will split the group in 3 based on that 3 factors.

UPDATE: Uploaded my SlideDeck, in case you want to take a look/ comment/ re-use: PowerShell Training slide deck

2 thoughts on “My PowerShell training. :)

  1. Thanks for comment, mjolinor. 🙂 It’s not that I forgot it, I hardly use it myself so I decided not to mention it. Probably this is because we are still in XP age in our company, so the only provider I really use on daily basis is FileSystem… 😉

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s