SPS Cincinnati slidedeck

25
Ryan Dennis Senior SharePoint Engineer, MCTS, MCITP – Information Control Corporation SharePointRyan.com The Power is in the Shell, Use it Wisely!

description

 

Transcript of SPS Cincinnati slidedeck

Page 1: SPS Cincinnati slidedeck

Ryan DennisSenior SharePoint Engineer, MCTS, MCITP – Information Control CorporationSharePointRyan.com

The Power is in the Shell, Use it Wisely!

Page 2: SPS Cincinnati slidedeck

2 | SharePoint Saturday Cincinnati 2011

Housekeeping Please remember to complete and return

your evaluation form

Drawings for raffle prizes will take place in the general session room after the last session of the day

Follow SharePoint Saturday Cincinnati on Twitter @spscincinnati

Page 3: SPS Cincinnati slidedeck

Thanks to Our Sponsors!Platinum

Gold

Silver

Page 4: SPS Cincinnati slidedeck

4 | SharePoint Saturday Cincinnati 2011

About the Speaker Ryan Dennis, MCTS, MCITP Senior SharePoint Engineer, ICC Blog: SharePointRyan.com Twitter: @SharePointRyan LinkedIn: linkedin.com/in/ryandennis Email: [email protected]

Page 5: SPS Cincinnati slidedeck

5 | SharePoint Saturday Cincinnati 2011

Why PowerShell? Admins: STSADM is probably going away, PowerShell goes

beyond just SharePoint –primary command-line for Windows Server, Exchange, etc.

Devs: You can leverage the Server Object Model to manipulate lists, list items, webs, sites, settings, etc.

BAs/PMs: Knowing what PowerShell is capable of will help your teams during builds, migrations, etc.

Recruiters: Looking for candidates who understand and use PowerShell will ensure that you’re getting people who are committed to learning and staying current.

Page 6: SPS Cincinnati slidedeck

6 | SharePoint Saturday Cincinnati 2011

Agenda Quick intro to Windows PowerShell Script Editors and Tools Using OOTB SharePoint 2010 PowerShell

Cmdlets (Demo 1) Extending PowerShell with basic scripts

and functions (Demo 2) Using XML, Get-Content and ForEach-

Object for advanced, bulk functionality (Demo 3)

Q&A

Page 7: SPS Cincinnati slidedeck

7 | SharePoint Saturday Cincinnati 2011

Windows PowerShell…is a task-based command-line shell and scripting language designed especially for Windows system administration

…has a task-based scripting language

…includes powerful object manipulation capabilities

…is built on the .NET Framework

Page 8: SPS Cincinnati slidedeck

8 | SharePoint Saturday Cincinnati 2011

Verb-NounPowerShell uses a Verb-Noun syntax for its Cmdlets Get-Something Set-Something New-Something Remove-Something

Page 9: SPS Cincinnati slidedeck

9 | SharePoint Saturday Cincinnati 2011

Get-Command & Get-Help While you can do a lot of the same things

as the typical command prompt, use Get-Command to see available commands

Use Get-Help <cmdlet> to get help information for a cmdlet

Page 10: SPS Cincinnati slidedeck

10 | SharePoint Saturday Cincinnati 2011

Using PowerShell Profiles PowerShell uses 2 profiles, a user specific

profile and a machine-wide profile… Use profiles to pre-load scripts, functions,

environmental variables, shell settings, aliases, etc.

Page 11: SPS Cincinnati slidedeck

11 | SharePoint Saturday Cincinnati 2011

Script Editors & Tools• Notepad.exe (Lame)• Notepad++ (Less Lame)• Windows PowerShell ISE (Pretty Good -

includes IntelliSense, Syntax highlighting)• Quest PowerGUI (Awesome – Adds

advanced debugging, and other cool things – don’t worry, I’ll show you!)

• Others…

Page 12: SPS Cincinnati slidedeck

12 | SharePoint Saturday Cincinnati 2011

SharePoint 2010 Cmdlets 500+ Cmdlets… MUCH better than STSADM.exe… Can automate complete installations and

configurations… Still doesn’t answer every scenario,

leaving gaps in functionality… Example: Get, New and Remove SharePoint

Groups – no cmdlet, easy to write a custom function though…

Page 13: SPS Cincinnati slidedeck

Creating a SharePoint Site Collection using out-of-the-box PowerShell Cmdlets

Demonstration

Page 14: SPS Cincinnati slidedeck

14 | SharePoint Saturday Cincinnati 2011

Demo Recap Used New-SPSite to create a new

SharePoint Site Collection… Stored the SPSite object into the $site

variable Created a $web variable from

$site.rootweb Used the $web variable to change the Site

Title using the SP Object Model Used Get-History and Pipeline to create a

simple script from our command history… Cool right, but what if we could make this

reusable??? (Hint: we can)

Page 15: SPS Cincinnati slidedeck

15 | SharePoint Saturday Cincinnati 2011

Extending PowerShell with Scripts and Functions PowerShell Scripts have .ps1 file

extension… Scripts and functions behave similarly if

not identically, but functions are more reusable…

Scripts can reference functions and cmdlets…

Functions can include other functions within them and can also reference cmdlets…

Page 16: SPS Cincinnati slidedeck

Using what we already learned and making it better.

Demonstration Two

Page 17: SPS Cincinnati slidedeck

17 | SharePoint Saturday Cincinnati 2011

Demo (2) Recap Used the following cmdlets in conjunction with

the pipeline to automagically build a function based on what we did in our first demonstration: Get-History Select-Object Out-File

Used Quest PowerGUI to edit our function by adding Parameters, eliminating hard-coded values…

Added comment-based help from PowerGUI Snippet…

Tried out our cool, new function…

Page 18: SPS Cincinnati slidedeck

18 | SharePoint Saturday Cincinnati 2011

Now, for the grand finale… You’ve seen some cool cmdlets, we’ve piped,

we’ve used Get-History, Select-Object, etc… There are a few cmdlets that can make bulk tasks

VERY easy and fun… Get-Content ForEach-Object

Using these in conjunction with other SharePoint cmdlets or custom functions can make your PowerShell life much more awesome…

Page 19: SPS Cincinnati slidedeck

19 | SharePoint Saturday Cincinnati 2011

What were those again? Get-Content

Can read the contents of a file… Can store the contents in a variable… Can process XML files… Can be piped into other cmdlets…

ForEach-Object Provides a way to loop through - and perform

an action on - each item in a collection.…

Page 20: SPS Cincinnati slidedeck

20 | SharePoint Saturday Cincinnati 2011

SPSSites.xml Syntax<?xml version="1.0" encoding="utf-8"?><Sites> <Site> <SiteTitle>Ryan Dennis</SiteTitle>

<SiteUrl>http://sps.adventureworks.com/rdennis</SiteUrl>

<Page><PageTitle>Home</PageTitle><PageUrl>Home.aspx</PageUrl><PageContent>HTML

Content</PageContent><PageLayout>Body

Only</PageLayout></Page>

</Site></Sites>

Page 21: SPS Cincinnati slidedeck

Using XML input to bulk create SharePoint Subsites using the Get-Content and ForEach-Object Cmdlets.

Demonstration Three

Page 22: SPS Cincinnati slidedeck

22 | SharePoint Saturday Cincinnati 2011

Demo (3) Recap Used the following cmdlets in an Advanced

Function to automate the provisioning of 22 SharePoint Sites, each with a new homepage with HTML content, all from XML input: Get-Content ForEach-Object New-SPWeb

Used Quest PowerGUI to edit our function by adding Parameters, eliminating hard-coded values…

Tried out our cool, new function…

Page 23: SPS Cincinnati slidedeck

23 | SharePoint Saturday Cincinnati 2011

The Power IS in the Shell, Use it Wisely! PowerShell is VERY powerful, be aware of

memory issues... Use dispose() method for Site and Web objects, or

better yet… Use Start-SPAssignment –Global to capture all

objects in the Global store, then use Stop-SPAssignment –Global to dispose of all objects…

Page 24: SPS Cincinnati slidedeck

24 | SharePoint Saturday Cincinnati 2011

Get-Resources

1. TechNet for general PowerShell information…2. Get-SPScripts.com3. Gary Lapointe4. Get-Help in a PowerShell window…5. SharePointRyan.com (yes, my blog)…

Page 25: SPS Cincinnati slidedeck

25 | SharePoint Saturday Cincinnati 2011

Got-Questions? Ryan Dennis, MCTS, MCITP Senior SharePoint Engineer, ICC Blog: SharePointRyan.com Twitter: @SharePointRyan LinkedIn: linkedin.com/in/ryandennis Email: [email protected]