Code Camp NZ 2011<br />#CCNZ<br />www.mscommunities.co.nz<br />
Introduction<br />PowerShell and SharePoint extensively covered on TechNet2010 Products administration by using Windows Po...
Session Agenda<br />Quick review of the basics and some useful Cmdlets<br />Walkthrough building a portal using PowerShell...
basics<br />PowerShell Basics<br />
How Do I?Work with PowerShell + SharePoint<br />SharePoint 2010 Management Shell<br />If you’re not using the SP2010 Manag...
What Do I Get?With PowerShell + SharePoint<br />SharePoint Cmdlets<br />245 listed on TechNet for SharePoint Foundation<br...
Cmdlets“…a lightweight command [for PowerShell]…”<br />Cmdlets return or operate on objects or collections<br />Use the pi...
Assemblies and ClassesPowerShell is not just limited to Cmdlets<br />Create objects with New-Object<br />$site = New-Objec...
Farm Administration<br />
Farm AdministrationAdding content to the farm<br />Adding Web ApplicationsNew-SPWebApplication<br />Update the Web Applica...
Farm AdministrationProtect and share the content<br />Backup and Restore<br />See the backup historyGet-SPBackupHistory<br...
demo<br />Farm Administration<br />
Site Administration<br />
Site Collections and SitesSites…Also known as SPWeb’s<br />Adding sub sitesNew-SPWeb<br />Change the site collection(s) an...
Site HierarchySPWeb has a lot of friends<br />The site’s hierarchy<br />Sub sites.Webs<br />Lists.Lists<br />Content Types...
demo<br />Site Administration<br />
Customisation Deployment	and Diagnostics<br />
Customisations and Deployment<br />Solutions<br />Retrieve solutions in farmGet-SPSolutionand download to file system.Solu...
Diagnostics and Troubleshooting<br />Developer Dashboard[Microsoft.SharePoint.Administration.SPWebService]	::ContentServic...
demo<br />Customisation Deployment	and Diagnostics<br />
tips<br />Resources and Tips<br />
Script Tips<br />Use and save scripts – they can be reused, maintained, reused, reused…<br />PS C:TENZ11PS> .myscript.ps1<...
Disposal TipsObject disposal is important to release memory<br />Easiest method is to useSPAssignment<br />Start-SPAssignm...
Scripts Won’t Run?Usually it will be permissions<br />What’s your Execution Policy?Set-ExecutionPolicyRestricted | AllSign...
Session TipsSome More Useful Cmdlets<br />Let the farm document itself usingExport-Clixmlhttp://bit.ly/psfarmdoc<br />UseO...
ResourcesUseful Blogs<br />NiklasGoudehttp://www.powershell.nu/<br />Zach Rosenfieldhttp://sharepoint.microsoft.com/Blogs/...
ResourcesOfficial Stuff<br />Windows PowerShell for SharePoint Server 2010http://technet.microsoft.com/en-us/library/ee662...
Track ResourcesInstallation<br />AutoSPInstallerhttp://autospinstaller.codeplex.com/<br />Install SharePoint Server 2010 b...
Content Slide<br />4th Annual Community SharePoint Conference<br />Business and Technical Tracks, all levels<br />Superb I...
Thanks to our sponsorsand partners!<br />Sponsor<br />Premier<br />Partners<br />Associated<br />Partners<br />Supporting<...
Upcoming SlideShare
Loading in...5
×

NZ Code Camp 2011 PowerShell + SharePoint

558

Published on

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

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

No Downloads
Views
Total Views
558
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
13
Comments
0
Likes
1
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-ExecutionPolicyhttp://technet.microsoft.com/en-us/library/ee176961.aspxAdd-SPShellAdminhttp://blogs.technet.com/b/heyscriptingguy/archive/2010/07/06/hey-scripting-guy-tell-me-about-permissions-for-using-windows-powershell-2-0-cmdlets-with-sharepoint-2010.aspx
  • Document Farm with export-Clixmlhttp://technet.microsoft.com/en-us/library/ff645391.aspxImport-CSV http://technet.microsoft.com/en-us/library/dd347665.aspx
  • NZ Code Camp 2011 PowerShell + SharePoint

    1. 1. Code Camp NZ 2011<br />#CCNZ<br />www.mscommunities.co.nz<br />
    2. 2. Introduction<br />PowerShell and SharePoint extensively covered on TechNet2010 Products administration by using Windows PowerShellhttp://technet.microsoft.com/en-us/library/ee806878.aspx<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=14.0.0.0, 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-Clixmlhttp://bit.ly/psfarmdoc<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-SPWebhttp://bit.ly/psimportcsv<br />
    26. 26. ResourcesUseful Blogs<br />NiklasGoudehttp://www.powershell.nu/<br />Zach Rosenfieldhttp://sharepoint.microsoft.com/Blogs/zach<br />Gary Lapointehttp://blog.falchionconsulting.com/<br />
    27. 27. ResourcesOfficial Stuff<br />Windows PowerShell for SharePoint Server 2010http://technet.microsoft.com/en-us/library/ee662539.aspx<br />Windows PowerShell for SharePoint Foundation 2010http://technet.microsoft.com/en-us/library/ee662510.aspx<br />STSADM to Windows PowerShell mappinghttp://technet.microsoft.com/en-us/library/ff621081.aspx<br />Microsoft.SharePoint Namespace (MSDN)http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.aspx <br />
    28. 28. Track ResourcesInstallation<br />AutoSPInstallerhttp://autospinstaller.codeplex.com/<br />Install SharePoint Server 2010 by using Windows PowerShell (SPModule)http://technet.microsoft.com/en-us/library/cc262839.aspx<br />The Wizard Likes His GUIDs (Configuring Service App’s without the Wizard)http://todd-carter.com/post/2010/04/26/The-Wizard-Likes-His-GUIDs.aspx<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 />
    1. A particular slide catching your eye?

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

    ×