• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

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







Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment
  • http://powerguivsx.codeplex.com/

SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience Presentation Transcript

  • SharePoint PowerShell for the Admin & Developer A Venn Diagram Experience #DogFoodCon Ryan Dennis | Ricardo Wilkins
  • What we’re barking about What is PowerShell? PowerShell and SharePoint – the evolution Scripts vs. code – comparison Business case walk through Code integration with PowerShell Architectural discussions #DogFoodCon
  • Meet the Mutts Ryan Dennis Ricardo Wilkins Consultant, Blue Chip Consulting Group Consultant, Blue Chip Consulting Group #DogFoodCon
  • What’s Your Breed? #DogFoodCon
  • What is 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 #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 #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, WhereObject, etc. • Use the built-in $_ variable to get values from the current object in the pipeline… • Let’s talk about this metaphorically…  #DogFoodCon
  • The Pipeline #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… #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 #DogFoodCon
  • Managing Solutions & Features Farm Solutions • • • • • Add-SPSolution Get-SPSolution Install-SPSolution Remove-SPSolution RemoveSPSolutionDeployme ntLock • Uninstall-SPSolution • Update-SPSolution #DogFoodCon Sandboxed Solutions • Add-SPUserSolution • Get-SPUserSolution • InstallSPUserSolution • RemoveSPUserSolution • UninstallSPUserSolution • UpdateSPUserSolution Features • • • • • Disable-SPFeature Enable-SPFeature Get-SPFeature Install-SPFeature Uninstall-SPFeature
  • 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 #DogFoodCon
  • The Evolution of SP Scripting • About 200 cmds • Over 500 • Over 700 • No native support PowerShell cmdlets PowerShell cmdlets for PowerShell* • PowerShell Version • PowerShell Version • STSADM was it 2.0 3.0 #DogFoodCon *You could use PowerShell by loading the Microsoft.SharePoint Assembly…
  • Pros & Cons of Script vs. Code Script Pros Quicker to write Easier to edit (open a file, edit it) No need to install a DLL to the server Can access the hundreds (thousands?) of other PowerShell cmdlets (Processes, Services, etc.) #DogFoodCon Code Cons Requires more time to develop& deploy Editing requires redeployment to server Requires a DLL installation
  • C# vs. PowerShell // 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) Both code snippets add or set the { // Grab the site and web Guid “CurrentUserSessionDuration” Guid sitedId = SPContext.Current.Site.ID; property in a Web. 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(); } $web = Get-SPWeb http://url } $web.Properties["CurrentUserSessionDuration"] = "60" } $web.Properties.Update() $web.Dispose() #DogFoodCon
  • The Business Case #DogFoodCon
  • The Personas Developer #DogFoodCon Admin Business Analyst / Project Manager
  • Get-Process –Name “Demo” | Start-Process #DogFoodCon
  • Developer + PS IIS Server SharePoint Call PowerShell SPList Log ListItems #DogFoodCon Change Titles PS1
  • SharePoint -Classic Web Part -Visual Web Part -SP2013 App Part #DogFoodCon
  • Call PowerShell #DogFoodCon
  • Call PowerShell #DogFoodCon http://ilovesharepoint.codeplex.com/wikipage?title=Execute%20PowerShell%20Script%20Action
  • -Files reside in e.g. C:Scripts -Scripts calling scripts as functions -Storing scripts in source control (TFS) -BA/PM viewing scripts vs code #DogFoodCon
  • SPList Log ListItems 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() } #DogFoodCon
  • SPList Log ListItems -BA/PM responsible for this list -Workflow can kickoff on New Item -Other apps, or Search, can pull from this list #DogFoodCon
  • Why is this worth chewing on? Separation of Devs vs Ops Devs maintain the UI Ops maintains the Title Change process Separation of Concerns / Single Responsibility pattern #DogFoodCon
  • Other things to chew on? PS in Office 365 PS in Azure PS Remoting PS Workflow #DogFoodCon
  • Barks from the Pack Thoughts? Would this model work for you? Other ideas? #DogFoodCon
  • >Get-Questions #DogFoodCon