Module 3 Administering and Automating SharePoint Module Overview • Configuring Central Administration • Administering SharePoint from the Command Line • Automating SharePoint Operations with Windows PowerShell Lesson 1: Configuring Central Administration • Administrative Options • Central Administration • Administrative Roles Administrative Options • Central Administration • Stsadm C:\Program Files\Common Files\Microsoft Shared\ web server extensions\14\BIN • Windows PowerShell • SharePoint 2010 Management Shell Supports Stsadm • Includes the BIN folder (STSADM) in its path configuration Preloads the SharePoint snap-ins for Windows PowerShell Central Administration • Web application Everything is done using the app pool identity for the Central Administration Web application: SP_Farm If something is not working, be sure SP_Farm has permissions • Local Administrators group on each SharePoint server • SQL Server permissions • Change the port Windows PowerShell Set-SPCentralAdministration -Port <PortNumber> • Blocks port 443 (SSL) • Blocks ports <1023 or >32767 Stsadm stsadm –o setadminport <PortNumber> Administrative Roles • Farm Administrators Security Users Manage the Farm Administrators group Capabilities No default access to sites or content, but can take ownership • Local Administrators Members of Farm Administrators Install products or applications, Web Parts, features • Service application administrators Click row of service application (don’t click the link!) Ribbon Administrators • Service application feature administrators • Site collection administrators and site owners Lesson 2: Administering SharePoint from the Command Line • SharePoint and Command-Line Administration • Stsadm • Introducing Windows PowerShell • Demonstration: Windows PowerShell Basics SharePoint and Command-Line Administration • SharePoint v1/v2 (2001–2003): No command-line interface • SharePoint 2007: Stsadm: 182 Commands (MOSS) • SharePoint 2010: More than 600 Windows PowerShell cmdlets Superset of Central Administration tasks Windows PowerShell 2.0 is required • Microsoft SharePoint Products Preparation Tool (PrerequisiteInstaller) Stsadm: Supported but deprecated Stsadm • Included but deprecated However, a few functions can be performed only with Stsadm • Buried in the Program Files folder C:\Program Files\Common Files\Microsoft Shared\ web server extensions\14\BIN Add to %PATH% or use SharePoint 2010 Management Shell • Command-line administration of SharePoint Must be run directly on the SharePoint server • Command syntax stsadm –o <OperationName> [-parameter <Value> …] • Get help stsadm -help <OperationName> Introducing Windows PowerShell • Command-line and task-based scripting language • A framework • Easy to learn, use, and adopt • Why use Windows PowerShell? The most powerful Windows-based command-line environment • Windows PowerShell vs. Stsadm Some overlap, but Windows PowerShell has unique capabilities including management of all new features Install and configure SharePoint 2010 Manage service applications Granular control of backup and restore Demonstration: Windows PowerShell Basics In this demonstration, you will learn to use: •Windows PowerShell •SharePoint 2010 Management Shell •cmdlets •Tab completion •Get-Help •Objects •Pipeline •Aliases •Variables Demonstration: Windows PowerShell Basics • SharePoint 2010 Management Shell • cmdlet (Get-Command) Not case sensitive Verb-Noun (Action-Object) format • Tab completion • Get-Help • Objects • Pipeline ( | ) • Aliases (Get-Alias) • Variables $variable = value String can be with single or double quotation marks $_ is the current object in the pipeline • Windows PowerShell on Microsoft TechNet Lesson 3: Automating SharePoint Operations with Windows PowerShell • SharePoint 2010 Management Shell • Delegate Permissions to Use Windows PowerShell • Examine the SharePoint Logical Structure Using Windows PowerShell • Create a SharePoint Intranet Using Windows PowerShell • Objects, Members, Properties, and Methods • Select, Sort, and Format Output • Filtering Objects • Typical Pipeline • Variables • Iteration (Looping) • Iteration in Scripts • Local, Global, and Remote Commands • Windows PowerShell Scripts SharePoint 2010 Management Shell • SharePoint 2010 Management Shell vs. Windows PowerShell Windows PowerShell available on clients SharePoint 2010 Management Shell only on SharePoint servers • SharePoint 2010 Management Shell has SharePoint snap-ins loaded automatically • Part of the SharePoint.ps1 profile located in %CommonProgramFiles%\Microsoft Shared\Web Server Extensions\14\Config\PowerShell\Registration • Windows PowerShell: Add-PSSnapin Microsoft.SharePoint.PowerShell ReuseThread option Stsadm (/BIN folder) in path Delegate Permissions to Use Windows PowerShell • Requirements to use Windows PowerShell to administer SharePoint WSS_ADMIN_WPG group on all servers in the farm SharePoint_Shell_Access database role on database Note: Setup user (SP_Admin) is not given rights by default • Delegate these permissions with Add-SPShellAdmin Add-SPShellAdmin -username <DOMAIN\user> -database (Get-SPContentDatabase <Content Database Name>) To run Add-SPShellAdmin, you must be • securityadmin server role on SQL instance • db_owner role for the database • Administrators membership on local computer • You must also be a site collection owner Set-SPSiteAdministration <SiteCollectionURL> -OwnerAlias <DOMAIN\user> -SecondaryOwnerAlias <DOMAIN\user> • Management Shell Run as Administrator may be required Examine the SharePoint Logical Structure Using Windows PowerShell • Examine the SharePoint Logical Structure with Get Get-SPFarm, Get-SPWebApplication, Get-SPSite, Get-SPWeb • Interface vs. Object Model Terminology • Using the Pipeline Create a SharePoint Intranet Using Windows PowerShell • Cmdlets Remove-SPWebApplication New-SPWebApplication New-SPContentDatabase New-SPSite New-SPWeb • Create the Intranet Web Application, Site Collection, and Site • Create a Content Database, Site Collection, and Site Objects, Members, Properties, and Methods • Cmdlets output objects • Objects can be stored in variables for later use or piped to a subsequent cmdlet for use as input by the cmdlet • Objects have members: properties and methods • A special kind of property is a collection • Get-Member object | Get-Member object | Get-Member –MemberType Methods object | Get-Member –MemberType Properties Select, Sort, and Format Output • Write-Output Writes object to the console: The default “end of pipeline” command Default properties are displayed • Select-Object (alias: Select) Select * displays all properties Select PropertyName [,PropertyName…] displays specific properties Get-SPWebApplication "http://intranet.contoso.com" | Get-SPSite -limit all | Get-SPWeb -limit all | Select URL,WebTemplate • Sort-Object (alias: Sort) Get-SPWebApplication "http://intranet.contoso.com" | Get-SPSite -limit all | Get-SPWeb -limit all | Sort URL [-descending] • Format-Table, Format-List (alias: fl) • Export-CSV, ConvertTo-XML, Out-GridView Filtering Objects • Where-Object (alias: Where, ?) Filters objects in the pipeline and passes only the filtered objects down the pipeline to the next cmdlet Get-SPWebApplication "http://intranet.contoso.com" | Get-SPSite -Limit ALL | Get-SPWeb -Limit ALL | Where-Object { $_.WebTemplate -eq "BLOG"} Server-side filtering (-Filter parameter) for specific properties: • SPWeb: Title and Template • SPSite and SPSiteAdministration: Owner, SecondaryContact, LockState • Use -Filter parameter (rather than Where-Object cmdlet) when possible Get-SPWebApplication "http://intranet.contoso.com" | Get-SPSite -Limit All | Get-SPWeb -Limit All -Filter {$_.Template -eq "BLOG"} • Operators Typical Pipeline • Get objects | Filter objects (Where) | Manipulate | Select | Sort | Format/Export/Out/Convert/Save Get-SPWebApplication "http://intranet.contoso.com" | GetSPSite -Limit ALL | Get-SPWeb -Limit ALL | Where-Object { $_.WebTemplate -eq "BLOG"} | Select URL,Title,WebTemplate, LastItemModifiedDate, Created | Sort LastItemModifiedDate | Export-CSV desktop\StaleBlogs.csv Variables • Variables start with $ Assign a variable $username = “CONTOSO\SP_Admin" $password = Read-Host "Enter the password: " AsSecureString Use a variable Write-Host "The user name is: " $username Write-Host "The password is: " $password • Note: This doesn’t work! Secure, one-way passwords only! • Windows PowerShell has built-in variables that you can call at run time $true, $false $home Many more: Get-Help about_automatic_variables Iteration (Looping) ForEach-Object (%, ForEach) • Iterates through each object in the pipeline • Sometimes, this is done implicitly by a cmdlet on the receiving side of the pipeline • For-Each is helpful where a cmdlet does not do its own iteration Get-SPWebApplication "http://intranet.contoso.com" | Get-SPSite "http://intranet.contoso.com/sites/Sales" | ForEach-Object { Enable-SPFeature "Ratings" -url $_.url -whatif } • Commonly used alias: % Iteration in Scripts • Syntax ForEach-Object ($variable in $array) { Actions } $i = ("HR", "Marketing") Creating an Array Parentheses are optional here ForEach($url in $i) Iterate through each item in the array Assign $url to the current item { Start loop actions New-SPContentDatabase -Name WSS_Content_Intranet_$url WebApplication http://intranet.contoso.com New-SPSite -Url http://intranet.contoso.com/sites/$url ContentDatabase WSS_Content_Intranet_$url -OwnerAlias CONTOSO\SP_Admin -Template "STS#0" } End loop actions Blank line starts execution Local, Global, and Remote Commands • Two types of commands: Local (“box”)—must be run on each box • Examples: Start-SPServiceInstance, Connect-SPConfigurationDatabase Global (“config db”) —run only once per farm • Examples: Set-SPWebApplication, New-SPSite • Remoting Windows PowerShell 2.0 features Windows PowerShell Remoting From your machine, perform Windows PowerShell commands and scripts on a remote machine Think “psexec.exe” Windows PowerShell Scripts • Creating scripts (.ps1) Windows PowerShell Integrated Scripting Environment (ISE) Readability • Can be multiline or one line: Multiline - Join commands on a single line with ; • Can be full cmdlets or aliases: Full cmdlets - ForEach-Object alias is % • Execution Set-ExecutionPolicy -unrestricted Read up on script signing • Schedule a Windows PowerShell script with Task Scheduler Command: PowerShell.exe Arguments: path\scriptname.ps1 • Scripts you’ll see in this course Lab A: Automating SharePoint with Windows PowerShell • Exercise 1: Adding SharePoint Functionality to Windows PowerShell • Exercise 2: Delegating the Ability to Use Windows PowerShell to Manage SharePoint • Exercise 3: Reporting Web and Site Collection Properties • Exercise 4: Creating Site Collections Using Windows PowerShell • Exercise 5: Creating and Updating Items Logon information Virtual machine 10174A-CONTOSO-DC-C 10174A-SP2010-WFE1-C Administrative user name CONTOSO\Administrator CONTOSO\SP_Admin Password Pa$$w0rd Pa$$w0rd Logon user name Estimated time: 30 minutes Scenario • You are responsible for ensuring that the SharePoint farm can be built consistently in both lab and production environments, and that the farm can be rebuilt in the event of a catastrophic failure. Additionally, you are required to produce weekly reports showing the webs and storage utilization of each site collection in the production farm. To meet these goals, you must build Windows PowerShell scripts that can automate SharePoint management tasks. Lab B: Administering SharePoint with Stsadm • Exercise 1: Executing Stsadm Commands Logon information Virtual machine 10174A-CONTOSO-DC-C 10174A-SP2010-WFE1-C Administrative user name CONTOSO\Administrator CONTOSO\SP_Admin Password Pa$$w0rd Pa$$w0rd Logon user name Estimated time: 20 minutes Scenario • Contoso’s policies encourage and in some cases mandate the automation of common tasks. As such, your Microsoft Office SharePoint Server 2007 environment had several Stsadm scripts that were used to create site collections and webs. Module Review and Takeaways • Review Questions