Top Banner
Getting Started with SharePoint + PowerShell Ryan Dennis @SharePointRyan www.SharePointRyan.com
20

Intro to SharePoint + PowerShell

Nov 18, 2014

Download

Technology

Ryan Dennis

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.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Intro to SharePoint + PowerShell

Getting Started with SharePoint + PowerShell

Ryan Dennis@SharePointRyan

www.SharePointRyan.com

Page 2: Intro to SharePoint + PowerShell

Enter POWERSAT at checkout to save $50 on any training course.

www.TRAINSIGNAL.com

Learn PowerShell. 24/7, Anywhere.

Page 3: Intro to SharePoint + PowerShell

SeeShell

http://www.codeowls.com/seeshell

Simple and EffectiveData Visualization

For PowerShell

Use Coupon CodePSSAT002

And save 20%

Page 4: Intro to SharePoint + PowerShell

About The Speaker

Ryan Dennis, MCTS, MCPD, MCITPSenior SharePoint Engineer @ ICC Microsoft Virtual Technology Specialist (vTSP)

www.SharePointRyan.com

@SharePointRyan

linkedin.com/in/sharepointryan

[email protected]

Page 5: Intro to SharePoint + PowerShell

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 6: Intro to SharePoint + PowerShell

Verb-Noun

PowerShell uses a Verb-Noun syntax for its Cmdlets• Get-Something

• Set-Something

• New-Something

• Remove-Something

Page 7: Intro to SharePoint + PowerShell

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 8: Intro to SharePoint + PowerShell

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 9: Intro to SharePoint + PowerShell

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 10: Intro to SharePoint + PowerShell

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 11: Intro to SharePoint + PowerShell

DEMONSTRATION

Creating a SharePoint Web Application using out-of-the-box PowerShell Cmdlets

Page 12: Intro to SharePoint + PowerShell

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

Page 13: Intro to SharePoint + PowerShell

DEMONSTRATION TWO

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

Page 14: Intro to SharePoint + PowerShell

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: Intro to SharePoint + PowerShell

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: Intro to SharePoint + PowerShell

DEMONSTRATION THREE

Using what we already learned and making it better.

Page 17: Intro to SharePoint + PowerShell

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…

Page 18: Intro to SharePoint + PowerShell

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 19: Intro to SharePoint + PowerShell

Get-Resources

1. TechNet for general PowerShell information…

2. The Hey, Scripting Guy! blog3. Get-SPScripts.com4. Gary Lapointe5. Get-Help in a PowerShell window…6. SharePointRyan.com (yes, my blog)…

Page 20: Intro to SharePoint + PowerShell

Got-Questions -?

Ryan Dennis, MCTS, MCPD, MCITPSenior SharePoint Engineer @ ICC Microsoft Virtual Technology Specialist (vTSP)

www.SharePointRyan.com

@SharePointRyan

linkedin.com/in/sharepointryan

[email protected]