introduction to powershell for sharepoint admins and developers

Post on 31-Jul-2015

212 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

     

               

 Online Conference

 June 17th and 18th 2015

WWW.SPBIZCONF.COM

Michael BlumenthalPSC Group

Introduction to PowerShell For SharePoint Admins and Developers

WWW.SPBIZCONF.COM

Who is Michael Blumenthal?

• Technical Evangelist, PSC Group• 20 years in IT Consulting• 12 years with SharePoint • 8 years with PowerShell• Twitter: @MichaelBL

     

               

 Online Conference

 June 17th and 18th 2015

No Compiling!

No Packaging!

Command Line Control!

Why PowerShell?

     

               

 Online Conference

 June 17th and 18th 2015

PowerShell  puts the SharePoint Engine at your fingertips!

• It’s Easy to Get Started!1• Learn the PowerShell Syntax2• PowerShell + SharePoint3• Real World Examples4• More Resources5

     

               

 Online Conference

 June 17th and 18th 2015

Chapter 1

IT’S EASY TO GET STARTED!

     

               

 Online Conference

 June 17th and 18th 2015

Getting Started with PowerShell

20032008,R22012, R2107, 8, 8.1, 10

WWW.SPBIZCONF.COM

The Command Line Window

WWW.SPBIZCONF.COM

WWW.SPBIZCONF.COM

The Integrated Script Editor

V2

WWW.SPBIZCONF.COM

PowerShell V3&4 ISE

WWW.SPBIZCONF.COM

POSH vs the SharePoint Mgmt Shells

     

               

 Online Conference

 June 17th and 18th 2015

Chapter 2

LEARN THE POWERSHELL SYNTAX!

WWW.SPBIZCONF.COM

Symbols, Keywords, and Syntax! Oh My!

• Variables1• Commands2• Piping3• Comparisons4• Flow Control5• Filtering6

WWW.SPBIZCONF.COM

Reading Symbols in Code

• (tal Guidance• Moe, Larry, and }• The universe started with the Big !• !Important• A # of Bacon and # Browns

WWW.SPBIZCONF.COM

1. Variables!

• Case Insensitive, Dynamic typing

$something

$true, $false, $null, $profile

$myMessage= “Hello, World”

1

     

               

 Online Conference

 June 17th and 18th 2015

WWW.SPBIZCONF.COM

2. Commands are called cmdlets.

Verb-Noun

Built-in, Extensible

Get-Help & Help

Get-Member

WWW.SPBIZCONF.COM

     

               

 Online Conference

 June 17th and 18th 2015

Discoverability

WWW.SPBIZCONF.COM

3. The Power of Piping!

Output Of Command 1

Input of Command 2

|

WWW.SPBIZCONF.COM

Example

WWW.SPBIZCONF.COM

4. Dial zero for an…4

Operator

-eq -le-ne -like-gt -notlike-ge -match-lt -notmatch

WWW.SPBIZCONF.COM

Example

WWW.SPBIZCONF.COM

5. Taking Control of the Flow

• For (Init;Test;Repeat) {Commands}• for($i=1; $i -le 10; $i++) {Write-Host $i}For• Foreach (Item in Collection) {Commands}• Foreach ($web in $site.AllWebs) {$web.Title}ForEach• If (Test) {Commands} • if ($web.Title –ne “”) {Write-Host $web.Title}

If• While (Condition){Commands}• while($val -ne 3){$val++; Write-Host $val}While

     

               

 Online Conference

 June 17th and 18th 2015

Example

WWW.SPBIZCONF.COM

6. Where-Object

•Where {<Test>}Syntax

• V1&2:Dir | Where {$_.Name –like 

“B*”}• V3:Dir | where Name –like B*

Example

WWW.SPBIZCONF.COM

Executing Scripts

.\filename.ps1

Set-ExecutionPolicy Unrestricted

     

               

 Online Conference

 June 17th and 18th 2015

Chapter 3

POWERSHELL + 

SHAREPOINT

WWW.SPBIZCONF.COM

Version of SharePoint?

O365

D/L SOMC•Get GLP Scripts

SP2007

Get Scripts

2010/2013

Run SMC

Get PoSh Cmdlets for SharePoint

WWW.SPBIZCONF.COM

Using SharePoint Cmdlets in the ISE

O365: Import-Module microsoft.online.sharepoint.Powershell

On Prem 2010+:C:\...\14 or 15\CONFIG\POWERSHELL\Registration\SharePoint.ps1

2007:[void][System.Reflection.Assembly]::

LoadWithPartialName("Microsoft.SharePoint")

WWW.SPBIZCONF.COM

Highlights from the SharePoint Object Model 

SPField

SPListItem 

SPList

SPWeb

SPWebApplication

SPFarm

SPSite

     

               

 Online Conference

 June 17th and 18th 2015

WWW.SPBIZCONF.COM

On-Prem is simpler

Get-SPSite $url

• Use Farm Account or grant access with Add-SPShellAdmin

     

               

 Online Conference

 June 17th and 18th 2015

A Word About Memory Management

SPWeb SPSite

Inline In Script

 Dispose

     

               

 Online Conference

 June 17th and 18th 2015

     

               

 Online Conference

 June 17th and 18th 2015

Chapter 4

REAL WORLD EXAMPLES

WWW.SPBIZCONF.COM

Real World Examples

• Check the Farm Version• Check Versioning on all document

Libraries• Create List Items• Export Web App Properties to a file• Bulk Site Creation

WWW.SPBIZCONF.COM

What’s your Farm Version?

PS C:\Users\Administrator> $(get-SPFarm).BuildVersion

Major Minor Build Revision----- ----- ----- --------14 0 6109 5002

WWW.SPBIZCONF.COM

Get a Web and Explore it!

$web = get-spweb http://server/path

THEN

$web

     

               

 Online Conference

 June 17th and 18th 2015

WWW.SPBIZCONF.COM

Check Doc Lib Versioning Settingsfunction global:show-all-doclibs ($web){$web.Lists | where-object {($_.Hidden -ne $true) -and ($_.BaseType -eq "DocumentLibrary")} }

function global:show-all-doclib-versettings ($web)

{show-all-doclibs ($web) |select-object -property Title, EnableVersioning, MajorVersionLimit, EnableMinorVersions,MajorWithMinorVersionsLimit,forceCheckout}

$site = get-spsite “http://server/path”

show-all-doclib-versettings $site.RootWeb

     

               

 Online Conference

 June 17th and 18th 2015

WWW.SPBIZCONF.COM

Practical Uses• Bulk Create Sites1• List Item CRUD2• Create data for test cases3• Associate Workflows with a List4• Work across site collections5

• Deployment Scripting6• Identify files that won’t upload7

WWW.SPBIZCONF.COM

More Practical Uses• Sync Wep App Properties8• Install SharePoint9• Repeatably Manage Content10• Update Field Definitions11• Report on Security12

WWW.SPBIZCONF.COM

Create a List Item Server-Side

WWW.SPBIZCONF.COM

Audio Alerts

• Stick this at the end of your long running script:

$Voice = new-object -com SAPI.SpVoice $Voice.Speak(“Deployment is done!")

     

               

 Online Conference

 June 17th and 18th 2015

Bulk Site Creation

Site Definitions in V. Studio• Not an answer by themselves• Define site content• Intended for reuse– Mismatch to one time need

• CAML and PITA• Harder: Making it data driven• Change Site Def -> Recreate Site

PowerShell & Excel & UI

• Well suited for one time “blow in’s”

• Define the site template in the UI or use standard

• Save as a template– Even pub sites - sometimes• PowerShell has easy loops• Data driven from a CSV• Changes -> Mod Scripts

WWW.SPBIZCONF.COM

The PowerShell Solution

• Read the list of sites from CSV• Loop:– Create Site– Configure Site• Turn on Features• Set Master Pages, Welcome Page• Hide Libraries, set versioning• Adjust Navigation

– Add Lists, Libraries, Pages, Web parts, etc

• Loop again & again if needed – iterative!

     

               

 Online Conference

 June 17th and 18th 2015

Chapter 5

MORE RESOURCES

     

               

 Online Conference

 June 17th and 18th 2015

     

               

 Online Conference

 June 17th and 18th 2015

     

               

 Online Conference

 June 17th and 18th 2015

     

               

 Online Conference

 June 17th and 18th 2015

     

               

 Online Conference

 June 17th and 18th 2015

In Review• It’s Easy to Get Started!1• Learn the PowerShell Syntax2• PowerShell + SharePoint3• Real World Examples4• More Resources5

Start Scripting Today!

WWW.SPBIZCONF.COM

Please fill in my session feedback form available from the ‘Session Resources’ tab

on my session window.

Why not join us in October at

Michael BlumenthalTechnical Solution EvangelistPSC Group, LLC

• Contact me at: • MBlumenthal@psclistens.com• MichaelBlumenthal.me• Twitter: @MichaelBL• Yammer.com/SPYam

top related