powershell for the anxious itpro

21
PowerShell for the Anxious ITPro: A Journey down the rabbit hole Jason Himmelstein Senior Technical Director, SharePoint @ sharepointlhorn http://blog.sharepointlonghorn.com

Upload: jason-himmelstein

Post on 07-Nov-2014

1.143 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: PowerShell for the Anxious ITPro

PowerShell for the Anxious ITPro:A Journey down the rabbit hole

Jason HimmelsteinSenior Technical Director, SharePoint

@sharepointlhornhttp://blog.sharepointlonghorn.com

Page 2: PowerShell for the Anxious ITPro

2009 Atrion Networking Corporation

Jason’s contact & vitals

• 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: [email protected]

• Author of Developing Business Intelligence Apps for SharePoint– http://bit.ly/SharePointBI

Page 3: PowerShell for the Anxious ITPro

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

Page 4: PowerShell for the Anxious ITPro

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

Page 5: PowerShell for the Anxious ITPro

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

Page 6: PowerShell for the Anxious ITPro

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

Page 7: PowerShell for the Anxious ITPro

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

Page 8: PowerShell for the Anxious ITPro

2009 Atrion Networking Corporation

The Basics

•The "hardware"• PowerShell Console vs PowerShell ISE

•The terminology

• Shell• Command-lets - "cmdlets"• Variables• Pipeline• Scripts• Functions• Modules

Page 9: PowerShell for the Anxious ITPro

2009 Atrion Networking Corporation

Core Principles

• members• objects• pipelines• verb-noun• dot sourcing• parsing

Page 10: PowerShell for the Anxious ITPro

Simple Hard Demos

ShellPowerShell ISE

ProfilesModules

TranscriptAdd-Server2Farm

Page 11: PowerShell for the Anxious ITPro

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 ISE\IDE, 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?

Page 12: PowerShell for the Anxious ITPro

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 IDE\ISE and expect everything to

work

Page 13: PowerShell for the Anxious ITPro

2009 Atrion Networking Corporation

Practical Application

• Get help• Format your output• Output PowerShell to a file• Create file • Use variables• Get and use Date\Time stamp• Append text to a file• Use an if\else loop

Page 14: PowerShell for the Anxious ITPro

Easy to Medium Demos

CommandUsing a variable

With query for pathWith try\catch & output logging

USB Copy ScriptNew-ServerPrep

Page 15: PowerShell for the Anxious ITPro

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

Page 16: PowerShell for the Anxious ITPro

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!

Page 17: PowerShell for the Anxious ITPro

Wicked Hard Demos

Output-oneNoteGet-QuotaInfo

Create-DomainAccountsNew-PSProfile

Update-hostsfilenew-ms_ssa

New-farm

Page 18: PowerShell for the Anxious ITPro

Questions & Answers

Page 19: PowerShell for the Anxious ITPro

Handy information• Jason’s info

– http://blog.sharepointlonghorn.com – [email protected]– @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/

Page 20: PowerShell for the Anxious ITPro

2009 Atrion Networking Corporation

Win my book!

…and if you don’t win, GO BUY IT!

http://bit.ly/SharePointBI

Page 21: PowerShell for the Anxious ITPro

2009 Atrion Networking Corporation

Jason’s contact & vitals

• 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: [email protected]

• Author of Developing Business Intelligence Apps for SharePoint– http://bit.ly/SharePointBI