spsatx slides (widescreen)

27
Get-Command –Module Microsoft.SharePoint.PowerShell Ryan Dennis | MCTS, MCPD, MCITP SharePoint Solutions Architect, Focal Point Solutions The Power is in the Shell, use it wisely!

Upload: ryan-dennis

Post on 18-Nov-2014

2.172 views

Category:

Technology


0 download

DESCRIPTION

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. In this demo filled session, 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 or 2013 environment.

TRANSCRIPT

Page 1: Spsatx slides (widescreen)

Get-Command –Module Microsoft.SharePoint.PowerShell

Ryan Dennis | MCTS, MCPD, MCITPSharePoint Solutions Architect, Focal Point Solutions

The Power is in the Shell, use it wisely!

Page 2: Spsatx slides (widescreen)

2 | SharePoint Saturday Austin 2013

• Please turn off all electronic devices or set them to vibrate• If you must take a phone call, please do so in the hall• Wi-Fi is available, you will need your Guest ID/password

(at registration desk)• Feel free to tweet and blog during sessions. Remember to follow

@SPSATX and tag #SPSATX in your tweets!

THANK YOU FOR BEING A PART OF SHAREPOINT SATURDAY AUSTIN!

SharePoint Saturday Austin is hosted bythe Austin SharePoint User Group

(@AustinSPUG)

Page 3: Spsatx slides (widescreen)

PLEASE FILL OUT SESSION EVALUATIONS AND

THANK YOU FOR ATTENDING!

Page 4: Spsatx slides (widescreen)

4 | SharePoint Saturday Austin 2013

THANKS TO OUR SPONSORS!

Page 5: Spsatx slides (widescreen)

5 | SharePoint Saturday Austin 2013

ABOUT THE SPEAKER

Ryan Dennis, MCTS, MCPD, MCITPSharePoint Solutions ArchitectFocal Point Solutions

Father Husband

Drummer Geek

www.focalpointsolutions.co

www.sharepointryan.com

@SharePointRyan

linkedin.com/in/sharepointryan

[email protected]

Page 6: Spsatx slides (widescreen)

6 | SharePoint Saturday Austin 2013

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 7: Spsatx slides (widescreen)

7 | SharePoint Saturday Austin 2013

VERB-NOUN

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

Quick Tip!Use Get-Verb

to find approved

verbs!

Page 8: Spsatx slides (widescreen)

8 | SharePoint Saturday Austin 2013

• While you can do a lot of the same things as the typical command prompt, use Get-Command to see available commands– Get-Command –Module Microsoft.SharePoint.PowerShell

will show you all SharePoint Cmdlets• Use Get-Help <cmdlet> to get help information for a cmdlet– Get-Help <cmdlet> -Examples will show you examples for a

cmdlet

GET-COMMAND & GET-HELP

Quick Tip!Add Help to your scripts

and functions!

Page 9: Spsatx slides (widescreen)

9 | SharePoint Saturday Austin 2013

• PowerShell uses 2 profiles, a user specific profile and a machine-wide profile…

• Use profiles to pre-load snap-ins, scripts, functions, environmental variables, shell settings, aliases, etc.

USING POWERSHELL PROFILES

Quick Tip!Use New-Item $Profile –type file –force to

create a profile!

Page 10: Spsatx slides (widescreen)

10 | SharePoint Saturday Austin 2013

SCRIPT EDITORS & TOOLS

• Notepad.exe (Lame)• Notepad++ (Less Lame)• Windows PowerShell ISE (Pretty Good - includes IntelliSense,

Syntax highlighting, MUCH better with PowerShell V3)• Quest PowerGUI (Awesome – Adds advanced debugging, and

other cool things)• Visual Studio + PowerGUI Extensions (Probably best option,

can integrate with Source Control, etc.)• Others…

Page 11: Spsatx slides (widescreen)

11 | SharePoint Saturday Austin 2013

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

• SharePoint 2013– 700+ Cmdlets!

• 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…

SHAREPOINT CMDLETS

Page 12: Spsatx slides (widescreen)

12 | SharePoint Saturday Austin 2013

• Pros:– Allows administrators to work with SP2013 without server access via a

web browser– The default security is restrictive rather than permissive; zero

authentication rules means no users have access to anything– All that is required to run PSWA is a properly-configured PowerShell

Web Access gateway, and a client device browser that supports JavaScript and accepts cookies

• Cons:– No profile means there is no good way to auto-load SharePoint Snap in

or other scripts, functions or variables– Requires Windows Server 2012

POWERSHELL WEB ACCESS & SHAREPOINT 2013

For more on PSWA, go here! (don’t worry, it’s TechNet) http://bit.ly/x18ztj

Page 13: Spsatx slides (widescreen)

13 | SharePoint Saturday Austin 2013

SUPPORTED BROWSERS AND DEVICES

Chrome

Android

Windows Phone

Firefox

iPadiPhone

Safari InternetExplore

r

Page 14: Spsatx slides (widescreen)

14 | SharePoint Saturday Austin 2013

• We’re going to try something new today…• Let’s try to do a technical demo and presentation using ONLY a

browser and a PowerShell editor!

SURPRISE!

Page 15: Spsatx slides (widescreen)

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

Page 16: Spsatx slides (widescreen)

16 | SharePoint Saturday Austin 2013

DEMO RECAP

• Used Get-SPSite to get a SharePoint Site Collection…• Stored the SPSite object into the $site variable• Created a $web variable from $site.rootweb• Used Get-Member to view Methods and Properties associated with

the Web• Viewed and changed properties on the $web object using

PowerShell• Used the $web variable to change the Site Title using the SP Object

Model• Had some fun!

Page 17: Spsatx slides (widescreen)

DEMONSTRATION TWOCreating a new PowerShell Function for reusability

Page 18: Spsatx slides (widescreen)

18 | SharePoint Saturday Austin 2013

DEMO RECAP

• Used the previous demo example to create a basic function using PowerShell ISE V3

• Added and demonstrated Comment-based help and parameters• Tried it out• Had more fun!

Page 19: Spsatx slides (widescreen)

19 | SharePoint Saturday Austin 2013

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 20: Spsatx slides (widescreen)

20 | SharePoint Saturday Austin 2013

• 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

NOW, FOR THE GRAND FINALE…

Page 21: Spsatx slides (widescreen)

21 | SharePoint Saturday Austin 2013

• 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.…

WHAT WERE THOSE AGAIN?

Page 22: Spsatx slides (widescreen)

22 | SharePoint Saturday Austin 2013

<?xml version="1.0" encoding="utf-8"?><Sites>

<SiteAdmins><User>adventureworks\rdennis</User><User>adventureworks\spfarm</User>

</SiteAdmins><!-- root site --><Site Create=“true">

<SiteTitle>Home</SiteTitle><SiteUrl>/</SiteUrl><Page IsHomePage="true">

<PageTitle>Home</PageTitle><PageUrl>Home.aspx</PageUrl><PageLayout>Blank Web Part Page</PageLayout>

</Page></Site>

SPSSITES.XML SYNTAX

Page 23: Spsatx slides (widescreen)

DEMONSTRATION THREEAutomating the provisioning of bulk sites and pages using XML input

Page 24: Spsatx slides (widescreen)

24 | SharePoint Saturday Austin 2013

DEMO RECAP

• Used the following cmdlets in an Advanced Function to automate the provisioning of 5 SharePoint Sites, each with several Publishing Pages, all from XML input:– Get-Content– ForEach-Object– New-SPWeb– Write-Progress

• Used Windows PowerShell ISE V3 to edit our function by adding Parameters, eliminating hard-coded values…

• Tried out our cool, new function…• Checked out the sites and pages

Page 25: Spsatx slides (widescreen)

25 | SharePoint Saturday Austin 2013

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 26: Spsatx slides (widescreen)

26 | SharePoint Saturday Austin 2013

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. Twitter using #PowerShell7. SharePointRyan.com (yes, my blog)…

Page 27: Spsatx slides (widescreen)

27 | SharePoint Saturday Austin 2013

GOT-QUESTIONS | START-ASKING

Ryan Dennis, MCTS, MCPD, MCITPSharePoint Solutions ArchitectFocal Point Solutions

www.focalpointsolutions.co

www.sharepointryan.com

@SharePointRyan

linkedin.com/in/sharepointryan

[email protected]