Upload
ryan-dennis
View
211
Download
3
Embed Size (px)
DESCRIPTION
Ryan DennisSenior SharePoint Engineer, MCTS, MCITP – Information Control CorporationSharePointRyan.com
The Power is in the Shell, Use it Wisely!
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
Thanks to Our Sponsors!Platinum
Gold
Silver
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]
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.
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
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
8 | SharePoint Saturday Cincinnati 2011
Verb-NounPowerShell uses a Verb-Noun syntax for its Cmdlets Get-Something Set-Something New-Something Remove-Something
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
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.
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…
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…
Creating a SharePoint Site Collection using out-of-the-box PowerShell Cmdlets
Demonstration
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)
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…
Using what we already learned and making it better.
Demonstration Two
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…
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…
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.…
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>
Using XML input to bulk create SharePoint Subsites using the Get-Content and ForEach-Object Cmdlets.
Demonstration Three
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…
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…
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)…
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]