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
Busin...
Meet the Mutts
Ryan Dennis

Ricardo Wilkins

Consultant, Blue Chip Consulting Group Consultant, Blue Chip Consulting Group...
What’s Your Breed?

#DogFoodCon
What is PowerShell?
…is a task-based command-line shell and
scripting language designed especially for
Windows system admi...
PowerShell deals with Objects,
not Strings
• In order to find out what you can and cannot do or
see on an object, use the ...
The Pipeline
• PowerShell passes objects, that is – when you do
something like Get-Process, you’re retrieving process
obje...
The Pipeline

#DogFoodCon
SharePoint 2010 Cmdlets
• 500+ Cmdlets…
• MUCH better than STSADM.exe…

• Can automate complete installations and
configur...
As a Developer, why do I
care?
• Not always necessary to write code
• Use PowerShell to handle things you could
do in C#
•...
Managing Solutions & Features
Farm Solutions
•
•
•
•
•

Add-SPSolution
Get-SPSolution
Install-SPSolution
Remove-SPSolution...
Retrieving SharePoint Objects
• Multiple ways to get a Site Object using
PowerShell…
• $Site = Get-SPSite
• $Site = New-Ob...
The Evolution of SP Scripting

• About 200 cmds
• Over 500
• Over 700
• No native support
PowerShell cmdlets
PowerShell cm...
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...
C# vs. PowerShell
// register controls
protected TextBox TextBoxMinutesPerSession;
protected LinkButton LinkButtonUpdate;
...
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 view...
SPList
Log
ListItems

function Write-SPAppLogItem {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][System.String]$W...
SPList
Log
ListItems

-BA/PM responsible for this list
-Workflow can kickoff on New Item
-Other apps, or Search, can pull ...
Why is this worth chewing on?
Separation of Devs vs Ops
Devs maintain the UI
Ops maintains the Title Change process

Separ...
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
Upcoming SlideShare
Loading in...5
×

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

961

Published on

http://www.sharepointcowbell.com

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
961
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • http://powerguivsx.codeplex.com/
  • SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience

    1. 1. SharePoint PowerShell for the Admin & Developer A Venn Diagram Experience #DogFoodCon Ryan Dennis | Ricardo Wilkins
    2. 2. 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
    3. 3. Meet the Mutts Ryan Dennis Ricardo Wilkins Consultant, Blue Chip Consulting Group Consultant, Blue Chip Consulting Group #DogFoodCon
    4. 4. What’s Your Breed? #DogFoodCon
    5. 5. 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
    6. 6. 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
    7. 7. 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
    8. 8. The Pipeline #DogFoodCon
    9. 9. 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
    10. 10. 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
    11. 11. 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
    12. 12. 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
    13. 13. 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…
    14. 14. 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
    15. 15. 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
    16. 16. The Business Case #DogFoodCon
    17. 17. The Personas Developer #DogFoodCon Admin Business Analyst / Project Manager
    18. 18. Get-Process –Name “Demo” | Start-Process #DogFoodCon
    19. 19. Developer + PS IIS Server SharePoint Call PowerShell SPList Log ListItems #DogFoodCon Change Titles PS1
    20. 20. SharePoint -Classic Web Part -Visual Web Part -SP2013 App Part #DogFoodCon
    21. 21. Call PowerShell #DogFoodCon
    22. 22. Call PowerShell #DogFoodCon http://ilovesharepoint.codeplex.com/wikipage?title=Execute%20PowerShell%20Script%20Action
    23. 23. -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
    24. 24. 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
    25. 25. 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
    26. 26. 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
    27. 27. Other things to chew on? PS in Office 365 PS in Azure PS Remoting PS Workflow #DogFoodCon
    28. 28. Barks from the Pack Thoughts? Would this model work for you? Other ideas? #DogFoodCon
    29. 29. >Get-Questions #DogFoodCon
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×