PowerShell for SharePoint Developers and Administrators

Post on 24-Feb-2016

42 views 0 download

Tags:

description

PowerShell for SharePoint Developers and Administrators . Michael Blumenthal Magenic Technologies MichaelBl@Magenic.com. Who is Michael Blumenthal?. Sr. Consultant @ Magenic (MSFT Gold Partner) 16+ years in IT Consulting 9 years working with SharePoint - PowerPoint PPT Presentation

Transcript of PowerShell for SharePoint Developers and Administrators

PowerShell for SharePoint Developers and

Administrators

Michael BlumenthalMagenic Technologies

MichaelBl@Magenic.com

2

Who is Michael Blumenthal?

Sr. Consultant @ Magenic (MSFT Gold Partner)

16+ years in IT Consulting

9 years working with SharePoint

MCITP: SharePoint 2010; MCTS: WSS DevMCTS: MOSS Config & MCTS: WSS ConfigMCAD, MCSE, MCDBA, CAPM, INETA Champ

3

No Compiling!

No Packaging!

Just Code & Go!

Why PowerShell?

4

PowerShell puts the SharePoint Engine at your fingertips!

• It’s Easy to Get Started!1• Learn the PowerShell Syntax2• Real World Examples3• More Resources4• Demo!

5

Chapter 1

IT’S EASY TO GET STARTED!

Getting Started with PowerShell

Windows Server 2003• Download

Windows Server 2008• Install

Windows Server 2008 R2• Run (Add ISE)

7

8

POSH vs the SP2010 Mgmt Shell

9

10

Chapter 2

LEARN THE POWERSHELL SYNTAX!

Learn to use PowerShell with SharePoint!

Symbols & Keywords

Using the SharePoint API

Creating and Running Scripts

12

Symbols, Keywords, and Syntax! Oh My!

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

13

Punctuation PronunciationSymbol Called Symbol Called

$ Dollar sign, money _ Underscore

# Pound, hash [ ] Square Brackets

| Pipe, vertical bar . Dot, point, period

{ } Curly braces < > Angle Brackets

“ Double Quote, tick - Dash, hyphen, minus

: Colon % Percent sign

( ) Parentheses ; Semi-colon

+ Plus = Equals, is

! Bang, not /, \ Slash, backslash

Is “$#|” a “one dollar hash pipe”?

14

Variables begin with a $

• Case Insensitive, Dynamic typing

$foo

$true, $false, $profile

$foo = “Hello, World”

1

15

16

Commands are called cmdlets.Verb-Noun

Built-in, Extensible

Get-Help & Help

Get-Member

2

17

18

The Power of Piping!

Output Of Command

1

Input of Command

2|

3

Example

Making Comparisons4Operator Meaning Operator Meaning

-eq Equals -le Less Than or Equal To

-ne Not Equals -like Wildcard Match

-gt Greater Than -notlike Not (Wildcard Match)

-ge Greater Than or Equal To -match Reg. Exp. Match

-lt Less Than -notmatch Not (Reg. Exp. Match)

21

Taking Control of the Flow5

• 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

Example

23

Where-Object6

• Where {<Test>}Syntax

• Dir | Where {$_.Name –like “B*”}

Example

24

Using the SharePoint API

• Getting an SPSite1• Manipulating It2• Cleaning Up3

25

Highlights from the SharePoint Object Model

SPField

SPListItem

SPList

SPWeb

SPWebApplication

SPFarm

SPSite

26

Loading SharePoint DLLs

[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

27

Get a Site and Explore it!

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

THEN$site

28

29

Create a List Item

30

Practical Uses• Create Sites from the Command Line1• Add, Delete, Change Lists and List Items2• Create data for test cases3• Associate Workflows with a List4• Work across site collections5

• Update User Metadata in AD for better Profile Pages6• Identify files that won’t upload7

31

More Practical Uses• Sync Wep App Properties8• Deploy Solutions9• Repeatably Manage Content10• Update Field Definitions11• Edit MP3 Metadata, Make Flashcards12

32

A Word About Memory Management

SPWeb SPSite

Inline In Script

Dispose

33

34

Executing Scripts

.\filename.ps1

Set-ExecutionPolicy Unrestricted

35

Chapter 3

REAL WORLD EXAMPLES

36

Real World Examples

Check the Farm VersionCheck Versioning on all document LibrariesCreate List ItemsExport Web App Properties to a fileBulk Site Creation

37

What’s your SP2010 Version?

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

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

38

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

39

40

Clear a List

Make a mess:

Clean it up!

41

42

43

Bulk Site Creation

Site Definitions in V. StudioNot an answer by themselvesDefine site contentIntended for reuse

Mismatch to one time needCAML and PITAHarder: Making it data drivenChange Site Def -> Recreate Site

PowerShell & Excel & UI

Well suited for one time “blow in’s”Define the site template in the UI or use standardSave as a template

Even pub sitesPowerShell has easy loopsData driven from a CSVChanges -> Mod Scripts

44

The PowerShell Solution

Read the list of sites from CSVLoop:

Create SiteConfigure Site

Turn on FeaturesSet Master Pages, Welcome PageHide Libraries, set versioningAdjust Navigation

Add Lists, Libraries, Pages, Web parts, etcLoop again & again if needed – iterative!

45

Chapter 4

MORE RESOURCES

Resources

SharePoint + Reflector / Decompiler

Microsoft Resources

3rd Party Resources

47

Use a Decompiler to see MSFT’s Code!

OR

ILSpy.netdotPeek (jetbrains)justDecompile (Telerik)Reflector(RedGate)Others…NO

LONGER

FREE

49

50

51

52

53

54

JEFF HICKS

55

Resources Summary

MSFTReverse Engineering SharePoint PagesBruce Payette’s Book v2PowerShell Product Team Blog

CommunityCodePlex: PSBBs My Blog at BlumenthalIT.NetJeff Hicks - http://www.jdhitsolutions.com/ POSHCODE.ORG

56

PowerShell puts the SharePoint API at your fingertips!

It’s Easy to Get Started!

Learn & Use the PowerShell Syntax

More Resources

In Review…

57

Chapter 5

See the power of PowerShell + SharePoint!

DEMO!

58

Contact Me!

Blog about SharePoint at http://blog.BlumenthalIT.net

Twitter: @MichaelBL

MichaelBL@magenic.com & http://www.Magenic.com

59

Gold

• Application Integration

• Data Platform• Digital

Marketing• Portals and

Collaboration• Software

Development• Web

Development

Silver

• Application Lifecycle Management

• Business Intelligence

• Content Management

• Mobility• Search

SDPS Program Member

Enterprise SP Development Experts

Numerous Microsoft Competencies, including:

PS: We’re hiring!