NZ Code Camp 2011 PowerShell + SharePoint


Published on

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

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
  • NZ Code Camp 2011 PowerShell + SharePoint

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