Painless PowerShell for SharePoint Admins Rick Taylor Special Thanks to our Platinum Sponsor …and our Gold Sponsor • Who am I??? • Who am I ?????????? • Rick Taylor, MCSE, MCT • SharePoint architect, formerly with Microsoft SharePoint Platform Architecture Team for SharePoint Online (O365) • Contact • http://blogs.technet.com/ritaylor • Twitter: @SLKRCK • SlickRickIsTheMan@Hotmail.com Agenda • What is Windows PowerShell • Windows PowerShell basics • Windows PowerShell scripts for administrators What is Windows PowerShell? • Command-line interface and scripting language used for SharePoint Server administration • Complements CMD • Extends STSADM • Uses XML & Objects • Built on the .Net Framework Windows PowerShell Basics • cmdlet • pronounced "command-let“ • More than 500 cmdlets for SharePoint alone ©2012 Microsoft Corporation. All rights reserved. SharePoint 2013 Nouns and Verbs • 774 Total commands • Nouns start with SP • 334 Nouns Windows PowerShell Basics • cmdlets = verbs (actions) & nouns (objects) • Combine the two to build specific commands • Examples • Get-SPSite • Get = Verb • SPSite = Noun Getting the list of SharePoint cmdlets • Get a list of all commands: • Get-Command –noun sp* • Get help for a specific command: • Get-Help <cmdlet> Windows PowerShell for SharePoint Command Builder http://www.microsoft.com/resources/TechNet/en-us/Office/media/WindowsPowerShell/WindowsPowerShellCommandBuilder.html Getting the list of SharePoint cmdlets • For more detailed help add the following parameters: • Get-Help <cmdlet> -full • Get-Help <cmdlet> -examples • Get-Help <cmdlet> -detailed Differences in Get-help: -full Differences in Get-help: -detailed Differences in Get-help: -examples -WhatIf • Evaluate what happens without side-effects ©2012 Microsoft Corporation. All rights reserved. Adding SharePoint Snap-In to ISE Checking out Windows PowerShell DEMO PowerShell Scripts • Build scripts to easily execute through common commands and tasks • Develop using PowerShell ISE or other shells • Schedule using Task Scheduler. SharePoint Basic Site Structure Site Structure Creation Command New-SPManagedAccount New-SPWebApplication New-SPContentDatabase New-SPManagedPath New-SPSite New-SPWeb Description Registers a new managed account Creates a new web application Creates a new content database for a web application Creates a managed path Creates a new site collection Creates a new web within a site collection Permissions for Shell Admins for Backup and Restore Farm component Member of Administrators group on the local computer Member of Farm Administrators SharePoint group Full Control on backup folder Farm Yes No Yes Service application Yes No Yes Content database Yes No Yes Site collection No Yes Yes Site, list, document library Yes No Yes PowerShell Scripts • Examples: • Activate a feature across multiple site collections • Provisioning of Managed Accounts • Creating of New Sites • Backup all Site Collections in Farm Service Application Setup/Configuration Cmdlet Name Example Get-SPServiceInstance $svc = (Get-SPServiceInstance | ? {$_.TypeName -eq "Managed Metadata Web Service"}) Start-SPServiceInstance if ($svc.Status –eq "Disabled") { $svc | Start-SPServiceInstance } while($svc.Status -ne "Online") { Write-Host "Waiting to provision"; sleep 5; } New-SP*ServiceApplication PS C:\> Get-Command New-SP*ServiceApplication New-SP*ServiceApplicationProxy PS C:\> Get-Command New-SP*ServiceApplicationProxy New-SPServiceApplicationProxyGroup Add-SPServiceApplicationProxyGroupMember New-SPServiceApplicationProxyGroup "Demo" $mms = Get-SPServiceApplicationProxy | ?{$_.TypeName -eq "Managed Metadata Service Connection"} Add-SPServiceApplicationProxyGroupMember -Identity "Demo" Member $mms Connect-SPOService –Url https://apps2013demo-admin.sharepoint.com –credential administrator@apps2013demo.onmicrosoft.com PS C:\windows\system32> get-command -noun spo* | Group Noun Count Name Group ----- -------4 SPOUser {Add-SPOUser, Get-SPOUser, Remove-SPOUser, S... 2 SPOService {Connect-SPOService, Disconnect-SPOService} 1 SPOAppErrors {Get-SPOAppErrors} 1 SPOAppInfo {Get-SPOAppInfo} 3 SPODeletedSite {Get-SPODeletedSite, Remove-SPODeletedSite, ... 2 SPOExternalUser {Get-SPOExternalUser, Remove-SPOExternalUser} 7 SPOSite {Get-SPOSite, New-SPOSite, Remove-SPOSite, R... 4 SPOSiteGroup {Get-SPOSiteGroup, New-SPOSiteGroup, Remove-... 2 SPOTenant {Get-SPOTenant, Set-SPOTenant} 1 SPOTenantLogEntry {Get-SPOTenantLogEntry} 1 SPOTenantLogLastAvaila... {Get-SPOTenantLogLastAvailableTimeInUtc} 1 SPOWebTemplate {Get-SPOWebTemplate} 1 SPOUpgradeEvaluationSite {Request-SPOUpgradeEvaluationSite} Additional PowerShell Resources • Windows PowerShell for SharePoint Foundation 2010 • http://technet.microsoft.com/enus/library/ee662510(office.14).aspx • Windows PowerShell Getting Started Guide • http://msdn.microsoft.com/enus/library/aa973757(VS.85).aspx • Windows PowerShell Cheat Sheet • http://refcardz.dzone.com/refcardz/windows-powershell • STSADM to Windows PowerShell mapping • http://technet.microsoft.com/en-us/library/ff621084.aspx • Zach Rosenfield’s blog • http://sharepoint.microsoft.com/blogs/zach/default.aspx