You may have heard of PowerShell, but do you know what it’s capable of? Gone are the days of long, painful STSADM batch files – we have Windows PowerShell, and it’s here to stay.Learn how you can use Windows PowerShell both to perform simple one-off tasks as well as complex, bulk operations. Leveraging the Object Model gives Administrators and Developers the ability to do in a few lines of code what would’ve taken a lot more work (and probably a Developer or two) in the WSS platform.You’ll see how you can get started with PowerShell, and you will hopefully leave with not only a greater understanding of what PowerShell is – but what it is capable of and how you can start using it to automate tasks in your SharePoint 2010 environment.
2. Learn PowerShell. 24/7, Anywhere.
Enter POWERSAT at checkout to save
$50 on any training course.
www.TRAINSIGNAL.com
3. SeeShell
Simple and Effective
Data Visualization
For PowerShell
Use Coupon Code
PSSAT002
And save 20%
http://www.codeowls.com/seeshell
4. About The Speaker
Ryan Dennis, MCTS, MCPD, MCITP
Senior SharePoint Engineer @ ICC
Microsoft Virtual Technology Specialist (vTSP)
www.SharePointRyan.com
@SharePointRyan
linkedin.com/in/sharepointryan
ryan@sharepointryan.com
5. 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
6. Verb-Noun
PowerShell uses a Verb-Noun syntax for its
Cmdlets
• Get-Something
• Set-Something
• New-Something
• Remove-Something
7. 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
8. 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.
9. 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…
10. 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…
11. Creating a SharePoint Web Application using out-of-the-box
PowerShell Cmdlets
DEMONSTRATION
12. Demo Recap
• Used New-SPWebApplication to create a
new SharePoint Web Application…
• Stored the SPWebApplication object into
the $webapp variable
• Used Get-Member to view Methods and
Properties associated with the Web
Application
13. Creating a SharePoint Site Collection using out-of-the-box
PowerShell Cmdlets
DEMONSTRATION TWO
14. 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. 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…
16. Using what we already learned and making it better.
DEMONSTRATION THREE
17. Demo 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. 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…
19. Get-Resources
1. TechNet for general PowerShell information…
2. The Hey, Scripting Guy! blog
3. Get-SPScripts.com
4. Gary Lapointe
5. Get-Help in a PowerShell window…
6. SharePointRyan.com (yes, my blog)…
Please add the sponsor LOGO (if it exists), name, short description and any urls if necessary to the designated areas. CITPG will add the sponsor level.
Start from a new PowerShell Window:Create a Site Collection:$site = New-SPSite –Url http://sps.adventureworks.com –Template “CMSPUBLISHING#0” –Name “SharePoint Saturday Cincinnati” –OwnerAlias isg1085\\spfarm –SecondaryOwnerAlias isg1085\\sharepointryan –Verbose$site | gm$web = $site.rootweb$web.title = “Modified”$web.update()Get-History | Out-File c:\\scripts\\demo.ps1
Start from a new PowerShell Window:Create a Site Collection:$site = New-SPSite –Url http://sps.adventureworks.com –Template “CMSPUBLISHING#0” –Name “SharePoint Saturday Cincinnati” –OwnerAlias isg1085\\spfarm –SecondaryOwnerAlias isg1085\\sharepointryan –Verbose$site | gm$web = $site.rootweb$web.title = “Modified”$web.update()Get-History | Out-File c:\\scripts\\demo.ps1
Create a script first, then talk about making it reusable by adding parameters and making it a functionCreate a dummy function on the shell to show how they work, then move into PowerGUIAdd some output with Write-HostAdd comment-based help