sharepoint powershell for the admin and developer - a venn diagram experience

29
#DogFoodCon SharePoint PowerShell for the Admin & Developer A Venn Diagram Experience Ryan Dennis | Ricardo Wilkins

Upload: ricardo-wilkins

Post on 07-Nov-2014

1.053 views

Category:

Technology


1 download

DESCRIPTION

http://www.sharepointcowbell.com

TRANSCRIPT

Page 1: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

SharePoint PowerShell for the Admin & DeveloperA Venn Diagram Experience

Ryan Dennis | Ricardo Wilkins

Page 2: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

What is PowerShell?PowerShell and SharePoint – the evolutionScripts vs. code – comparisonBusiness case walk throughCode integration with PowerShellArchitectural discussions

What we’re barking about

Page 3: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

www.SharePointCowBell.com

@ricardo303

@spcowbell

about.me/ricardowilkins

Ricardo WilkinsConsultant, Blue Chip Consulting Group

Ryan DennisConsultant, Blue Chip Consulting Group

www.SharePointRyan.com

@SharePointRyan

linkedin.com/in/sharepointryan

[email protected]

Meet the Mutts

Page 4: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

What’s Your Breed?

Page 5: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

…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

What is PowerShell?

Page 6: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

PowerShell deals with Objects, not Strings

• In order to find out what you can and cannot do or see on an object, use the Get-Member cmdlet

• Get-Member will return all Methods and Properties associated with whatever item you pass to it

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

Page 7: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

The Pipeline

• PowerShell passes objects, that is – when you do something like Get-Process, you’re retrieving process object(s) – you can then pipe that output, or that process object to Stop-Process, Select-Object, Where-Object, etc.

• Use the built-in $_ variable to get values from the current object in the pipeline…

• Let’s talk about this metaphorically…

Page 8: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

The PipelineGet-DogBreed

Result: 2 Breeds

Get-DogBreed | Where-Object {$_.Group –eq “Herding”}

Get-DogBreed | Where-Object {$_.Group –eq “Herding” –and $_.Name –match “*shepherd*”}

Result: 25 Breeds

Result: 178 Breeds

Page 9: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

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 10: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

As a Developer, why do I care?• Not always necessary to write code

• Use PowerShell to handle things you could do in C#

• Don’t write console apps, write PowerShell Scripts!

• Some clients don’t allow managed code deployments, but PowerShell is A-OK

Page 11: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

Managing Solutions & Features

Farm Solutions• Add-SPSolution• Get-SPSolution• Install-SPSolution• Remove-SPSolution• Remove-

SPSolutionDeploymentLock

• Uninstall-SPSolution• Update-SPSolution

Sandboxed Solutions• Add-SPUserSolution• Get-SPUserSolution• Install-

SPUserSolution• Remove-

SPUserSolution• Uninstall-

SPUserSolution• Update-

SPUserSolution

Features• Disable-SPFeature• Enable-SPFeature• Get-SPFeature• Install-SPFeature• Uninstall-SPFeature

Page 12: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

Retrieving SharePoint Objects•Multiple ways to get a Site Object using

PowerShell…• $Site = Get-SPSite• $Site = New-Object Microsoft.SharePoint.SPSite($Url)

•Multiple ways to get a Web Object using PowerShell…• $Web = $Site.RootWeb• $Web = $Site.OpenWeb()• $Web = Get-SPWeb

Page 13: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

The Evolution of SP Scripting

• About 200 cmds• No native support

for PowerShell*• STSADM was it

• Over 500 PowerShell cmdlets

• PowerShell Version 2.0

• Over 700 PowerShell cmdlets

• PowerShell Version 3.0

*You could use PowerShell by loading the Microsoft.SharePoint Assembly…

Dennis, Ryan
You like this?
Ricardo Wilkins
Yes!
Page 14: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

Pros & Cons of Script vs. Code

Script ProsQuicker to writeEasier to edit (open a file, edit it)No need to install a DLL to the serverCan access the hundreds (thousands?) of other PowerShell cmdlets (Processes, Services, etc.)

Code ConsRequires more time to develop& deployEditing requires redeployment to serverRequires a DLL installation

Page 15: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

// register controls protected TextBox TextBoxMinutesPerSession; protected LinkButton LinkButtonUpdate; // Create a click event handler LinkButtonUpdate.Click += new EventHandler(LinkButtonUpdate_Click); void LinkButtonUpdate_Click(object sender, EventArgs e) { // Grab the site and web Guid Guid sitedId = SPContext.Current.Site.ID; Guid webID = SPContext.Current.Web.ID; //create and dispose of spweb and spsite objects using (SPSite oSPSite = new SPSite(sitedId)) { 

using (SPWeb oWeb = oSPSite.OpenWeb(webID)) 

{ //Set the custom web property to the

textbox value

oWeb.Properties["CurrentUserSessionDuration"] = TextBoxMinutesPerSession.Text;

oWeb.Properties.Update(); }

} }

C# vs. PowerShell

$web = Get-SPWeb http://url$web.Properties["CurrentUserSessionDuration"] = "60"$web.Properties.Update()$web.Dispose()

Both code snippets add or set the “CurrentUserSessionDuration”

property in a Web.

PowerShell

C#

Page 16: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

The Business CaseContoso just purchasedAdventureWorks – Yay!

AdventureWorks Intranet Contains 100’s of site

collections, thousands of sub sites

Renaming them all through

the UI would take (dog) days

Page 17: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

The Personas

Developer Admin

Business Analyst /

Project Manager

Page 18: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

Get-Process –Name “Demo” | Start-Process

Page 19: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

Developer + PS

IIS ServerSharePoint

PS1

ChangeTitles

LogListItems

CallPowerShell

SPList

Page 20: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

SharePoint

-Classic Web Part-Visual Web Part-SP2013 App Part

Page 21: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

CallPowerShell

Page 22: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodConhttp://ilovesharepoint.codeplex.com/wikipage?title=Execute%20PowerShell%20Script%20Action

CallPowerShell

Page 23: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

-Files reside in e.g. C:\Scripts-Scripts calling scripts as functions-Storing scripts in source control (TFS)-BA/PM viewing scripts vs code

Page 24: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

function Write-SPAppLogItem {[CmdletBinding()]Param([Parameter(Mandatory=$true)][System.String]$WebUrl,[Parameter(Mandatory=$true)][System.String]$ListName)$web = Get-SPWeb $WebUrl$list = $web.Lists[$ListName]$item = $list.Items.Add()$date = Get-Date$item["Title"] = "Operation completed successfully: $date"$item.Update()$web.Dispose()}

LogListItems

SPList

Page 25: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

LogListItems

SPList

-BA/PM responsible for this list-Workflow can kickoff on New Item-Other apps, or Search, can pull from this list

Page 26: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

Why is this worth chewing on?

Separation of Devs vs OpsDevs maintain the UIOps maintains the Title Change process

Separation of Concerns / Single Responsibility pattern

Page 27: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

Other things to chew on?

PS in Office 365PS in AzurePS RemotingPS Workflow

Page 28: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

Barks from the Pack

Thoughts? Would this model work for you?Other ideas?

Page 29: SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

#DogFoodCon

>Get-Questions