1. PowerShell for the Anxious ITPro:
Jason Himmelstein
Senior Technical Director, SharePoint
@sharepointlhorn
http://blog.sharepointlonghorn.com
2. 2009 Atrion Networking Corporation
• Senior Technical Director, SharePoint at Atrion
• Microsoft vTSP
– virtual Technology Solutions Professional
• SharePoint Foundation Logger
– http://spflogger.codeplex.com
• Blog: www.sharepointlonghorn.com
• Twitter: @sharepointlhorn
• LinkedIn: www.linkedin.com/in/jasonhimmelstein
• SlideShare: http://www.slideshare.net/jasonhimmelstein
• Email: jase@sharepointlonghorn.com
• Author of Developing Business Intelligence Apps for SharePoint
– http://bit.ly/SharePointBI
3. 2009 Atrion Networking Corporation
Agenda
• Introduction
• What is it?
• History
• The Why
• Basics
• Core principles
• Do's & Do not's
• Practical application
• Functional Explanation
• Sebisms
• Wrap up
4. 2009 Atrion Networking Corporation
What is it?
• It isn't:
– Fire and forget
– A packaged executable
– Developer-centric
– Too hard for an ITPro
• It is:
– Command line environment
– Microsoft technology holistic
– A swiss army knife with a chain saw
– The future of ITPro's world
5. 2009 Atrion Networking Corporation
What is it?
• Windows PowerShell is Microsoft's task automation framework, consisting of a command-
line shell and associated scripting language built on .NET Framework. PowerShell provides full
access to COM and WMI, enabling administrators to perform administrative tasks on both local
and remote Windows systems.
– Definition from Wikipedia
• What is it really
– PowerShell is an object-based, not text-based, command-line interface for Microsoft
Technologies
• What does that mean:
– Results in PowerShell can be acted upon, not just read from
6. 2009 Atrion Networking Corporation
History
• Started internally at Microsoft in 2002
• Demo'ed at PDC in 2003 - early stage
• Private beta
• Public Beta in June 2005
• April 2006 changed the name to PowerShell
• PowerShell v1 for RTW on Nov 14 2006
• PowerShell v2 was released in Aug 2009 as a part of Win7 & Server 2008 R2
• PowerShell v3 was released as a part of Win8 & Server 2012
• PowerShell v4 is coming as a part of Server 2012 R2
7. 2009 Atrion Networking Corporation
The Why
• Why did Microsoft create PowerShell & move more to a
PowerShell world than a GUI world?
• What is it used for:
– Deployment
– Configuration
– Management
– Administration
– Development
8. 2009 Atrion Networking Corporation
The Basics
• The "hardware"
• PowerShell Console vs PowerShell ISE
• The terminology
• Shell
• Command-lets - "cmdlets"
• Variables
• Pipeline
• Scripts
• Functions
• Modules
11. 2009 Atrion Networking Corporation
The Do’s
• Use variables
• Only one thing at a time
• Comment your scripts
• Follow a verb-noun scripting format
• Create scripts using an ISEIDE, execute in shell
• Dispose of your objects code
• Test before using in Production
• Write re-usable scripts
• KISS method – Keep it simple, scripter!
…you thought I was going to call you stupid didn’t you?
12. 2009 Atrion Networking Corporation
Do Not’s
• Vary your variables
• Hard code your scripts
• Take code from the internet or vendor & just RUN in your
environment
• Assume that code is not harmful… it is.
• Run your code in an IDEISE and expect everything to work
13. 2009 Atrion Networking Corporation
Practical Application
• Get help
• Format your output
• Output PowerShell to a file
• Create file
• Use variables
• Get and use DateTime stamp
• Append text to a file
• Use an ifelse loop
14. Easy to Medium Demos
Command
Using a variable
With query for path
With trycatch & output logging
USB Copy Script
New-ServerPrep
15. 2009 Atrion Networking Corporation
Functional Explanation
• Get-verb
– Gets approved Windows PowerShell verbs
• Get-member
– Listing the Properties and Methods of a Command or Object
• Get-history
– If you didn’t start transcript, you can still review your history
before closing your Shell or ISE window
16. 2009 Atrion Networking Corporation
Sebism re: Try Catch
• Try catch
– From Seb Matthews:
• try – run the script elements within this block
– nice, safe bubble for running cmdlets that may fail
• catch – jump to this block (or blocks) if an error occurs in what you “try”
– bubble in which you can handle the error appropriately
– you can have multiple catch blocks which can be ordered by the nature of the
error – see my PowerTip about this
• finally – jump to this block after try or catch regardless of whether an error was
generated
– this block is really here to enable cleanup (such as object disposal)
– remember it runs regardless of the error state!
19. Handy information
• Jason’s info
– http://blog.sharepointlonghorn.com
– jase@sharepointlonghorn.com
– @sharepointlhorn
• Seb Matthews
– http://sebmatthews.com
• This Deck is available now at http://bit.ly/itpro-powershell
• SharePoSH Virtual Users Group
– http://www.shareposh.com/
• PowerShell.org
– http://www.powershell.org
• The Scripting Guy
– http://blogs.technet.com/b/heyscriptingguy/
20. 2009 Atrion Networking Corporation
…and if you don’t win,
GO BUY IT!
http://bit.ly/SharePointBI
21. 2009 Atrion Networking Corporation
• Senior Technical Director, SharePoint at Atrion
• Microsoft vTSP
– virtual Technology Solutions Professional
• SharePoint Foundation Logger
– http://spflogger.codeplex.com
• Blog: www.sharepointlonghorn.com
• Twitter: @sharepointlhorn
• LinkedIn: www.linkedin.com/in/jasonhimmelstein
• SlideShare: http://www.slideshare.net/jasonhimmelstein
• Email: jase@sharepointlonghorn.com
• Author of Developing Business Intelligence Apps for SharePoint
– http://bit.ly/SharePointBI