SlideShare a Scribd company logo
Boulos Dib
                            November 16, 2011
http://blog.boulosdib.com       @boulosdib
PS> Describe-Presenter
 Independent Consultant – Napeague Inc.
 Professional Software Development since 1983
 Few Facts
    First Personal Computer 1980 – TRS-80 III
    First Z80 based product (EPROM based Protocol Adaptor – 1984)
    First Commercial PC-DOS product (Telex on PCs – 1985)
    Started 16-bit Windows Development using Win 3.1
    Developed on: 8080/Z80, 68xxx, PDP/RSX,VAX-VMS and x86/x64 (C/C++/C#)
    Worked with PowerShell since Monad (2006)
    Worked with SharePoint since STS (2003)
    More facts
         Favorite sport – Windsurfing 
         Favorite hobby – Playing my sunburst Fender Stratocaster+ guitar.
         Favorite guitar players
             Wes Montgomery, Larry Carlton and Ritchie Blackmore (Deep Purple, Rainbow)
Agenda
 Quick PowerShell Review
 SharePoint 2010 Management Shell
 PowerShell (Functions, CmdLet)
 SharePoint CmdLets by Group
 Best Practices
 Sample Scripts
 Tools
 Resources
PowerShell Review
 Interactive Command Shell
 Programmatic Execution Environment
 Dynamic Scripting Language
 Extensible (CmdLets, .Net etc…)
 Hosted (i.e. NuGet/PowerGUI vsix)
 Management tool for Servers
Review - What is a shell
“A shell is the piece of software that lets you access the
functionality provided by the operating system. “

Bruce Payette - Co-Designer and Implementer of the
PowerShell language.

 Example
    Windows Explorer
    Command.com
    Cmd.exe
    Bash (Unix)
    PowerShell
Review - Consistent Environment
 Common Parameters
    -Verbose
    -Debug
    -WarningAction
    -WarningVariable
    -ErrorAction
    -ErrorVariable
    -OutVariable
    -OutBuffer

 Risk Mitigation Parameters (certainly critical in a production environment)
    What-If
    -Confirm

 Whildcard support.
    All names and parameter value can support wildcard.
 Pipeline
Where do I start
 Verb-XXNoun
    Verbs: Get, Set, New, Write, Read
    Nouns: Drive, Variable, Provider, Site, Collection
 Most important command
    Get-Help
        Get-Help *
        Get-Help *drive*
    Get-Member
    Get-Command
PowerShell
 Functions
 Scripts
 Error Handling
 Parameters
 Splatting


 Remoting
 PSSession
Functions
 Functions is a script block containing list of statements
 function small_files ($size = 100MB) {
        Get-ChildItem c: | where { $_.length -lt $size -and
         !$_.PSIsContainer}
    }

 To control how a function uses the pipeline, you use Begin,
  Process and End.
 function pipelineFunction {
    process {"The value is: $_"}
   }
   1,2,3 | pipelineFunction

 Advanced functions allow you to write CmdLets using scripts
  instead of compiled code.
Scripts
 A Script file is a text file with .ps1 extension containing
    one or more PowerShell command
   A Script is a simple mechanism to re-use functionality.
   To run a script on a remote computer, use the Invoke-
    Command and provide remote computer name as a
    parameter.
   Scripts can accept parameters.
   To run a script in the current session, we Dot-Source
    the . .Script1.ps1
   We can Scope Local or Global.
Error Handling
 Terminating vs. Nonterminating Errors
 Trap
 Throw – Sometime useful for parameters
    function hi ($name=$(throw '$name is required')) {"Hi
     $name"}
Errors Handling – as in C#
   try
   {
         $wc = new-object System.Net.WebClient
         $wc.DownloadFile("http://www.contoso.com/MyDoc.doc")
   }
   catch [System.Net.WebException],[System.IO.IOException]
   {
         unable to download MyDoc.doc from http://www.contoso.com."
   }
   catch
   {
         "An error occurred that could not be resolved."
   }
Snapins, Providers and Drives
 Get-PSProvider | Format-List Name, PSSnapin
 Get-PSSnapin
 Get-PSProvider
 Get-PSDrive
PowerShell Modules
 Get-Module –ListAvailable




 Import-Module ActiveDirectory
SharePoint Management Shell
 SharePoint Management Shell differs slightly from
  the Standard PowerShell:

 Runspace Threading
   $Host.Runspace.ThreadOptions = "ReuseThread“



 SharePoint Specific Snap-In
   Add-PSSnapin Microsoft.SharePoint.PowerShell
Threading & Proper Object
Disposal
 $Host.Runspace.ThreadOptions = "ReuseThread"


 Get-SPAssignment –Global
    $spWeb = Get-SPWeb -Identity $url
    $spWeb.TreeViewEnabled = $True
    $spWeb.Update()
 Stop-SPAssignment –Global
Sharepoint CmdLets Groups
 Farm
 Application
 Solution
 Site Collection
 Site
 List and ListItem
Farm
 Backup-SPFarm
 Get-SPFarm
 Restore-SPFarm
Web Application
 Get-SPWebApplication
 New-SPWebApplication
 Remove-SPWebApplication
 Set-SPWebApplication
Solutions
 Get-SPSolution
 Add-SPSolution
 Remove-SPSolution
 Install-SPSolution
 UnInstall-SPSolution
 Update-SPSolution
Site Collections
 Backup-SPSite
 Get-SPSite
 Move-SPSite
 New-SPSite
 Remove-SPSite
 Restore-SPSite
 Set-SPSite
Sites
 Export-SPWeb
 Get-SPWeb
 Import-SPWeb
 New-SPWeb
 Remove-SPWeb
 Set-SPWeb
Tools - Productivity
Tool                        Url
PowerGUI                    http://PowerGUI.org/
PowerTab                    http://powertab.codeplex.com/
Community Extensions        http://pscx.codeplex.com/
Quest ActiveRoles           http://www.quest.com/powershell/activeroles-
                            server.aspx/
ShowUI                      http://showui.codeplex.com/
Windows Automation Snapin   http://wasp.codeplex.com/
for PowerShell
Visual Studio Hosted
 NuGet
   http://nuget.org/
   http://nuget.codeplex.com/


 PowerGUI vsix
    http://powerguivsx.codeplex.com/


 StudioShell
    http://studioshell.codeplex.com/
Books – PowerShell
 PowerShell in Action                 Windows PowerShell 2.0 Bible
 Bruce Payette                        By Thomas Lee, Karl Mitschke,
 “The book from the authority on       Mark E. Schill, and Tome
  PowerShell”                           Tanasovski
                                        http://powertoe.wordpress.com/
                                        (Tome’s blog)
Books – PowerShell & SharePoint
 Automating Microsoft SharePoint          PowerShell for Microsoft
  2010 Administration with Windows          Sharepoint 2010 Administrators.
  PowerShell 2.0
 Gary Lapointe & Shannon Bray           Niklas Goude & Mattias Karlsson
 http://blog.falchionconsulting.com/    http://www.powershell.nu/
                                         http://mysharepointofview.com/
 http://sppowershell.com/

More Related Content

PPTX
PowerShell for SharePoint Admins
PPTX
PowerShell for sharepoint 2010 administrators
PPTX
PowerShell and SharePoint
PPTX
SP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
PPTX
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
PPTX
Intro to SharePoint + PowerShell
PPTX
Best Practices for creating WP REST API by Galkin Nikita
PPT
Introduction to Play Framework
PowerShell for SharePoint Admins
PowerShell for sharepoint 2010 administrators
PowerShell and SharePoint
SP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
SharePoint PowerShell for the Admin and Developer - A Venn Diagram Experience
Intro to SharePoint + PowerShell
Best Practices for creating WP REST API by Galkin Nikita
Introduction to Play Framework

What's hot (20)

PPTX
ASP.NET Core 1.0
PPTX
Best Practices for WordPress in Enterprise
PDF
Isomorphic WordPress Applications with NodeifyWP
PDF
Node.js to the rescue
PDF
Fluxible
KEY
WordPress APIs
PDF
Here Be Dragons - Debugging WordPress
PDF
Play Framework: The Basics
PDF
High Performance Drupal
PDF
JSON REST API for WordPress
PPTX
Extending ansible
PPTX
Play! Framework for JavaEE Developers
PDF
Laravel presentation
PPTX
Django rest framework
PDF
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
PPTX
Chef and PowerShell Desired State Configuration
PPTX
Intro to Laravel
PPT
Integration and Acceptance Testing
PDF
Embracing HTTP in the era of API’s
PPTX
Intro to Coldfusion
ASP.NET Core 1.0
Best Practices for WordPress in Enterprise
Isomorphic WordPress Applications with NodeifyWP
Node.js to the rescue
Fluxible
WordPress APIs
Here Be Dragons - Debugging WordPress
Play Framework: The Basics
High Performance Drupal
JSON REST API for WordPress
Extending ansible
Play! Framework for JavaEE Developers
Laravel presentation
Django rest framework
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
Chef and PowerShell Desired State Configuration
Intro to Laravel
Integration and Acceptance Testing
Embracing HTTP in the era of API’s
Intro to Coldfusion
Ad

Viewers also liked (20)

PPT
What i have learnt about technologies from the
PPTX
Assignment 11 (draft 2)
PPT
Dtq4_ita
DOCX
Tugas kimia dasar 1 part 2
PPT
Taddei classroom management
PPTX
Handelsbeleid in steden en gemeenten (UNIZO Burgemeestersonbijt 16/01/14)
PPT
PPT
Presentatie oefenzitting5
PPT
Game animals
PPTX
Front cover & contents page research
DOCX
PMSight References
PPTX
Asteroïde
PPTX
We didn't watch tv
PPTX
PDF
Corporate_Training at CETPA Campus for IBM AIX 6.1
DOCX
The real makalah ( reaksi kimia dalam larutan air )
PDF
36kr no.94
PPTX
Planning for draft 3
PPTX
PDF
Primero bmo presentation final
What i have learnt about technologies from the
Assignment 11 (draft 2)
Dtq4_ita
Tugas kimia dasar 1 part 2
Taddei classroom management
Handelsbeleid in steden en gemeenten (UNIZO Burgemeestersonbijt 16/01/14)
Presentatie oefenzitting5
Game animals
Front cover & contents page research
PMSight References
Asteroïde
We didn't watch tv
Corporate_Training at CETPA Campus for IBM AIX 6.1
The real makalah ( reaksi kimia dalam larutan air )
36kr no.94
Planning for draft 3
Primero bmo presentation final
Ad

Similar to PowerShell for SharePoint Developers (20)

PDF
Introduction to PowerShell
PPTX
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
PPTX
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
PPTX
Automating PowerShell with SharePoint
PPTX
Power shell training
PPTX
PPT
Powershell Seminar @ ITWorx CuttingEdge Club
PPTX
Wsv406 Advanced Automation Using Windows Power Shell2.0
PPTX
Post exploitation using powershell
PPTX
Harmonious Development: Via Vagrant and Puppet
PDF
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
PPTX
Get-Help: An intro to PowerShell and how to Use it for Evil
PDF
Release with confidence
PPTX
PowerShell-1
PPT
PowerShell Technical Overview
PPTX
Windows PowerShell - Billings .NET User Group - August 2009
PPTX
NZ Code Camp 2011 PowerShell + SharePoint
PPTX
Introduction to windows power shell in sharepoint 2010
PDF
One-Man Ops
PPT
PowerShell Remoting
Introduction to PowerShell
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
Brian Jackett: Managing SharePoint 2010 Farms with Powershell
Automating PowerShell with SharePoint
Power shell training
Powershell Seminar @ ITWorx CuttingEdge Club
Wsv406 Advanced Automation Using Windows Power Shell2.0
Post exploitation using powershell
Harmonious Development: Via Vagrant and Puppet
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Get-Help: An intro to PowerShell and how to Use it for Evil
Release with confidence
PowerShell-1
PowerShell Technical Overview
Windows PowerShell - Billings .NET User Group - August 2009
NZ Code Camp 2011 PowerShell + SharePoint
Introduction to windows power shell in sharepoint 2010
One-Man Ops
PowerShell Remoting

Recently uploaded (20)

PDF
Open folder Downloads.pdf yes yes ges yes
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PDF
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
01-Introduction-to-Information-Management.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Pharma ospi slides which help in ospi learning
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Business Ethics Teaching Materials for college
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Open folder Downloads.pdf yes yes ges yes
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
O7-L3 Supply Chain Operations - ICLT Program
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O5-L3 Freight Transport Ops (International) V1.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
01-Introduction-to-Information-Management.pdf
TR - Agricultural Crops Production NC III.pdf
Anesthesia in Laparoscopic Surgery in India
Pharma ospi slides which help in ospi learning
Microbial disease of the cardiovascular and lymphatic systems
Business Ethics Teaching Materials for college
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Microbial diseases, their pathogenesis and prophylaxis
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...

PowerShell for SharePoint Developers

  • 1. Boulos Dib November 16, 2011 http://blog.boulosdib.com @boulosdib
  • 2. PS> Describe-Presenter  Independent Consultant – Napeague Inc.  Professional Software Development since 1983  Few Facts  First Personal Computer 1980 – TRS-80 III  First Z80 based product (EPROM based Protocol Adaptor – 1984)  First Commercial PC-DOS product (Telex on PCs – 1985)  Started 16-bit Windows Development using Win 3.1  Developed on: 8080/Z80, 68xxx, PDP/RSX,VAX-VMS and x86/x64 (C/C++/C#)  Worked with PowerShell since Monad (2006)  Worked with SharePoint since STS (2003)  More facts  Favorite sport – Windsurfing   Favorite hobby – Playing my sunburst Fender Stratocaster+ guitar.  Favorite guitar players  Wes Montgomery, Larry Carlton and Ritchie Blackmore (Deep Purple, Rainbow)
  • 3. Agenda  Quick PowerShell Review  SharePoint 2010 Management Shell  PowerShell (Functions, CmdLet)  SharePoint CmdLets by Group  Best Practices  Sample Scripts  Tools  Resources
  • 4. PowerShell Review  Interactive Command Shell  Programmatic Execution Environment  Dynamic Scripting Language  Extensible (CmdLets, .Net etc…)  Hosted (i.e. NuGet/PowerGUI vsix)  Management tool for Servers
  • 5. Review - What is a shell “A shell is the piece of software that lets you access the functionality provided by the operating system. “ Bruce Payette - Co-Designer and Implementer of the PowerShell language.  Example  Windows Explorer  Command.com  Cmd.exe  Bash (Unix)  PowerShell
  • 6. Review - Consistent Environment  Common Parameters  -Verbose  -Debug  -WarningAction  -WarningVariable  -ErrorAction  -ErrorVariable  -OutVariable  -OutBuffer  Risk Mitigation Parameters (certainly critical in a production environment)  What-If  -Confirm  Whildcard support.  All names and parameter value can support wildcard.  Pipeline
  • 7. Where do I start  Verb-XXNoun  Verbs: Get, Set, New, Write, Read  Nouns: Drive, Variable, Provider, Site, Collection  Most important command  Get-Help  Get-Help *  Get-Help *drive*  Get-Member  Get-Command
  • 8. PowerShell  Functions  Scripts  Error Handling  Parameters  Splatting  Remoting  PSSession
  • 9. Functions  Functions is a script block containing list of statements  function small_files ($size = 100MB) {  Get-ChildItem c: | where { $_.length -lt $size -and !$_.PSIsContainer}  }  To control how a function uses the pipeline, you use Begin, Process and End.  function pipelineFunction {  process {"The value is: $_"} } 1,2,3 | pipelineFunction  Advanced functions allow you to write CmdLets using scripts instead of compiled code.
  • 10. Scripts  A Script file is a text file with .ps1 extension containing one or more PowerShell command  A Script is a simple mechanism to re-use functionality.  To run a script on a remote computer, use the Invoke- Command and provide remote computer name as a parameter.  Scripts can accept parameters.  To run a script in the current session, we Dot-Source the . .Script1.ps1  We can Scope Local or Global.
  • 11. Error Handling  Terminating vs. Nonterminating Errors  Trap  Throw – Sometime useful for parameters  function hi ($name=$(throw '$name is required')) {"Hi $name"}
  • 12. Errors Handling – as in C#  try  {  $wc = new-object System.Net.WebClient  $wc.DownloadFile("http://www.contoso.com/MyDoc.doc")  }  catch [System.Net.WebException],[System.IO.IOException]  {  unable to download MyDoc.doc from http://www.contoso.com."  }  catch  {  "An error occurred that could not be resolved."  }
  • 13. Snapins, Providers and Drives  Get-PSProvider | Format-List Name, PSSnapin  Get-PSSnapin  Get-PSProvider  Get-PSDrive
  • 14. PowerShell Modules  Get-Module –ListAvailable  Import-Module ActiveDirectory
  • 15. SharePoint Management Shell  SharePoint Management Shell differs slightly from the Standard PowerShell:  Runspace Threading  $Host.Runspace.ThreadOptions = "ReuseThread“  SharePoint Specific Snap-In  Add-PSSnapin Microsoft.SharePoint.PowerShell
  • 16. Threading & Proper Object Disposal  $Host.Runspace.ThreadOptions = "ReuseThread"  Get-SPAssignment –Global  $spWeb = Get-SPWeb -Identity $url  $spWeb.TreeViewEnabled = $True  $spWeb.Update()  Stop-SPAssignment –Global
  • 17. Sharepoint CmdLets Groups  Farm  Application  Solution  Site Collection  Site  List and ListItem
  • 19. Web Application  Get-SPWebApplication  New-SPWebApplication  Remove-SPWebApplication  Set-SPWebApplication
  • 20. Solutions  Get-SPSolution  Add-SPSolution  Remove-SPSolution  Install-SPSolution  UnInstall-SPSolution  Update-SPSolution
  • 21. Site Collections  Backup-SPSite  Get-SPSite  Move-SPSite  New-SPSite  Remove-SPSite  Restore-SPSite  Set-SPSite
  • 22. Sites  Export-SPWeb  Get-SPWeb  Import-SPWeb  New-SPWeb  Remove-SPWeb  Set-SPWeb
  • 23. Tools - Productivity Tool Url PowerGUI http://PowerGUI.org/ PowerTab http://powertab.codeplex.com/ Community Extensions http://pscx.codeplex.com/ Quest ActiveRoles http://www.quest.com/powershell/activeroles- server.aspx/ ShowUI http://showui.codeplex.com/ Windows Automation Snapin http://wasp.codeplex.com/ for PowerShell
  • 24. Visual Studio Hosted  NuGet  http://nuget.org/  http://nuget.codeplex.com/  PowerGUI vsix  http://powerguivsx.codeplex.com/  StudioShell  http://studioshell.codeplex.com/
  • 25. Books – PowerShell  PowerShell in Action  Windows PowerShell 2.0 Bible  Bruce Payette  By Thomas Lee, Karl Mitschke,  “The book from the authority on Mark E. Schill, and Tome PowerShell” Tanasovski  http://powertoe.wordpress.com/ (Tome’s blog)
  • 26. Books – PowerShell & SharePoint  Automating Microsoft SharePoint  PowerShell for Microsoft 2010 Administration with Windows Sharepoint 2010 Administrators. PowerShell 2.0  Gary Lapointe & Shannon Bray  Niklas Goude & Mattias Karlsson  http://blog.falchionconsulting.com/  http://www.powershell.nu/  http://mysharepointofview.com/  http://sppowershell.com/