Your SlideShare is downloading. ×
NZ Code Camp 2011 PowerShell + SharePoint
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

NZ Code Camp 2011 PowerShell + SharePoint


Published on

Nick Hadlee's session on PowerShell and SharePoint 2010 at Code Camp 2011.

Nick Hadlee's session on PowerShell and SharePoint 2010 at Code Camp 2011.

Published in: Technology

1 Like
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide
  • ForEach-Object and Where-Object both use $_ to represent the default objectWhere-ObjectFiltering the data streamUse operators to perform filter:-lt -- Less than-le -- Less than or equal to-gt -- Greater than-ge -- Greater than or equal to-eq -- Equal to-ne -- Not equal to-like - Like; uses wildcards for pattern matching
  • New Site CollectionFind out what templates are available Get-SPWebTemplate
  • Set-ExecutionPolicy
  • Document Farm with export-Clixml
  • Transcript

    • 1. Code Camp NZ 2011
    • 2. Introduction
      PowerShell and SharePoint extensively covered on TechNet2010 Products administration by using Windows PowerShell
      Session Goals
      Demystify PowerShell + SharePoint
      Examples of PowerShell in action
    • 3. Session Agenda
      Quick review of the basics and some useful Cmdlets
      Walkthrough building a portal using PowerShell
      Farm Administration
      Site Administration
      Deployment of Customisations
      Diagnostics and Troubleshooting
      Tips and Resources
    • 4. basics
      PowerShell Basics
    • 5. How Do I?Work with PowerShell + SharePoint
      SharePoint 2010 Management Shell
      If you’re not using the SP2010 ManagementShell make sure $host.Runspace.ThreadOptions = "ReuseThread"
      The PowerShell SharePoint Snapin provides the SP Cmdlets
      It’s always helpful include a reference to the Snapin
    • 6. What Do I Get?With PowerShell + SharePoint
      SharePoint Cmdlets
      245 listed on TechNet for SharePoint Foundation
      527 listed on TechNet for SharePoint Server
      (there’s more according to Get-Command)
    • 7. Cmdlets“…a lightweight command [for PowerShell]…”
      Cmdlets return or operate on objects or collections
      Use the pipeline | to pass and process objects$myObject | ForEach-Object { DoStuff $_ } ForEach %$myObject | Where-Object { $_ -gt 1 } Where ?
      I need some help? Some helpful Cmdlets:
      Get-HelpGet-Command $myObject | Get-Member
    • 8. Assemblies and ClassesPowerShell is not just limited to Cmdlets
      Create objects with New-Object
      $site = New-Object Microsoft.SharePoint.SPSite("http://tech.ed")
      Load other SharePoint or .NET assemblies
      [System.Reflection.Assembly]::LoadWithPartialName ("Microsoft.Office.Server.Search")
      [System.Reflection.Assembly]::Load ("Microsoft.Office.Server.Search, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
    • 9. Farm Administration
    • 10. Farm AdministrationAdding content to the farm
      Adding Web ApplicationsNew-SPWebApplication
      Update the Web ApplicationGet-SPWebApplication
      Adding Site CollectionsNew-SPSite
      Content Databases
      Adding new databasesNew-SPContentDatabase
      Attaching existing databasesMount-SPContentDatabase
      Test them using Test-SPContentDatabase
    • 11. Farm AdministrationProtect and share the content
      Backup and Restore
      See the backup historyGet-SPBackupHistory
      Farm and more granularBackup-SPFarmandRestore-SPFarm
      Site CollectionBackup-SPSiteandRestore-SPSite
      The SAGet-SPEnterpriseSearchServiceApplication
      Content SourcesGet-SPEnterpriseSearchCrawlContentSource
    • 12. demo
      Farm Administration
    • 13. Site Administration
    • 14. Site Collections and SitesSites…Also known as SPWeb’s
      Adding sub sitesNew-SPWeb
      Change the site collection(s) and site(s) properties
      Site Permissions and Users
      Add users and permissionsNew-SPUserandSet-SPUser
      Site collection administratorsSet-SPSiteAdministration
    • 15. Site HierarchySPWeb has a lot of friends
      The site’s hierarchy
      Sub sites.Webs
      Content Types.ContentTypes
      . . .
    • 16. demo
      Site Administration
    • 17. Customisation Deployment and Diagnostics
    • 18. Customisations and Deployment
      Retrieve solutions in farmGet-SPSolutionand download to file system.SolutionFile.SaveAs()
      Add/Deploy new solution to farmAdd-SPSolutionand Install-SPSolution
      Remove existing Solution to farmRemove-SPSolutionandUninstall-SPSolution
      Update existing farm solutionUpdate-SPSolution
      List all features in farmGet-SPFeature
      Install/Remove featureInstall-SPFeatureand Uninstall-SPFeature
      Activate/Deactivate featuresEnable-SPFeatureand Disable-SPFeature
    • 19. Diagnostics and Troubleshooting
      Developer Dashboard[Microsoft.SharePoint.Administration.SPWebService] ::ContentService.DeveloperDashboardSettings
      Listening to SharePoint’s logging service (ULS) Get-SPLogEvent
    • 20. demo
      Customisation Deployment and Diagnostics
    • 21. tips
      Resources and Tips
    • 22. Script Tips
      Use and save scripts – they can be reused, maintained, reused, reused…
      PS C:TENZ11PS> .myscript.ps1
      Use variables – they make scripts easier to read and maintain
      $siteUrl = "http://intranet"
      Use functions – pieces of logic in the script
      function Update-SiteTitle($site, $title) {
      $site.Title = $title
      Use comments
      # This explains what the script is doing which is helpful in the future
      Tab Ahead - PowerShell lets you tab to complete pathname and input
      Providing some output is helpful
      Write-Host “About to do stuff" vs. “About to do stuff"
      Build and test your scripts incrementally. Not directly in production!
    • 23. Disposal TipsObject disposal is important to release memory
      Easiest method is to useSPAssignment
      Start-SPAssignment -Global
      # Do stuff ...
      Stop-SPAssignment –Global
      You can use.Dispose()to clean up after yourself$site = Get-SPSite http://intranet; $site.Usage; $site.Dispose()
      Closing the PowerShell Console cleans up the session but it’s the lazy option
    • 24. Scripts Won’t Run?Usually it will be permissions
      What’s your Execution Policy?Set-ExecutionPolicyRestricted | AllSigned | RemoteSigned| Unrestricted
      Is UAC on? You may have to “Run as Administrator”
      Does the account have rights on databases? Add-SPShellAdmin-UserNamedemoSPUser-database SP2010_Content_TENZ
    • 25. Session TipsSome More Useful Cmdlets
      Let the farm document itself usingExport-Clixml
      UseOut-GridViewto output to a Grid UINeeds PowerShell ISE feature enabled (not on by default)
      UseImport-CSVto read from CSV files. Great input to other “creation” Cmdlets likeNew-SPUserand New-SPWeb
    • 26. ResourcesUseful Blogs
      Zach Rosenfield
      Gary Lapointe
    • 27. ResourcesOfficial Stuff
      Windows PowerShell for SharePoint Server 2010
      Windows PowerShell for SharePoint Foundation 2010
      STSADM to Windows PowerShell mapping
      Microsoft.SharePoint Namespace (MSDN)
    • 28. Track ResourcesInstallation
      Install SharePoint Server 2010 by using Windows PowerShell (SPModule)
      The Wizard Likes His GUIDs (Configuring Service App’s without the Wizard)
    • 29. Content Slide
      4th Annual Community SharePoint Conference
      Business and Technical Tracks, all levels
      Superb Internationally Renowned SharePoint Experts
    • 30. Thanks to our sponsorsand partners!