27
Introduction to Windows PowerShell for SharePoint Administrators Shane Young and Todd Klindt SharePoint Nerds Rackspace

Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

  • Upload
    others

  • View
    11

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

Introduction to Windows PowerShell for SharePoint Administrators

Shane Young and Todd Klindt

SharePoint Nerds

Rackspace

Page 2: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Who Am I?

• Shane Young

• Rackspace in Cincinnati

• SharePoint Server MVP 8 YEARS!

• Consultant, Trainer, Writer, & Speaker • [email protected]

• Blog

• http://msmvps.com/shane

• SharePoint Consulting

• http://sharepoint.Rackspace.com

• @ShanesCows

Page 3: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Who is this Todd guy?

• WSS MVP since 2006

• Speaker, writer, consultant, Aquarius, 4th in line for the British throne

• Personal Blogwww.toddklindt.com/blog

• Company web sitehttp://sharepoint.rackspace.com

[email protected]

• Twitter me! @toddklindt

• Weekly Netcast

• http://www.toddklindt.com/netcast

Page 4: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Agenda

• What is Windows PowerShell

• Windows PowerShell basics

• Windows PowerShell scripts for administrators

Page 5: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

What is Windows PowerShell?

• Command-line interface and scripting language used for SharePoint Server administration

• Compliments CMD

• Extends STSADM

• Uses XML & Objects

• Built on the .NET Framework

Page 6: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Why do we care?

• Complete command-line system that is far more powerful than any previous Windows-based command-line prompt environment.

• Provides:• More Control

• More Efficiency

• More Productivity

• More coolness

Page 7: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

What about STSADM?

• STSADM still available to support backwards compatibility.

• Whatever STSADM can do, PowerShell can do better!• Ability to run against SQL Snapshots, instead of production.

• More granular control for backup / restore.

Page 8: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Windows PowerShell Basics

• cmdlet • pronounced "command-let“

• single function that can be used separately or combined with other cmdlets to perform complex tasks and automate administration

Page 9: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Windows PowerShell Basics

• cmdlets = verbs (actions) & nouns (objects)

• Combine the two to build specific commands

• Examples

• Get-SPSite

• Get = Verb

• SPSite = Noun

Page 10: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

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>

• Get-Help <cmdlet> -example

Page 11: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

DEMO

PowerShell Basics

Page 12: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

PowerShell Scripts

• Build scripts to easily execute through common commands & tasks!

• Can be developed and scheduled using Windows Task Scheduler.

Page 13: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

PowerShell Scripts

• Examples:• Activate a feature across multiple site collections

• Provisioning of Managed Accounts

• Creating of New Sites

• Backup all Site Collections in Farm

Page 14: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Scripting Syntax

• Sample Script:• $password = Read-Host "What is the password for all accounts?" -

assecurestring ; Get-Content usernames.txt | ForEach-Object {New-SPManagedAccount -password $password -username litwareinc\$_; Set-SPManagedAccount -identity $_ -autogenerate -confirm:$False}

Syntax Description

$ Denotes a variable.

; Denotes completion of cmdlet, continue to next one.

| Sends the output of the preceding cmdlet to the next cmdlet.

ForEach-Object { } For each object, execute all the commands within the { }.

Page 15: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

DEMO

PowerShell Scripts

Page 16: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

General PowerShell tips

• It’s just a shell, spruce it up some

• Color

• Size

• Run as Admin

• Enable quick edit

• Use the included ISE

• Use a third party solution

Page 17: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Remoting

• Must be enabled on each server

• Nothing much to do on the client

• Two ways in

• Enter-PSSession

• Invoke-Command

• Use Enable-PSRemoting to enable

• Get-Help about_remoting

• Watch out for security settings

• Increase MaxMemoryPerShellMB

• PowerShell Web Access

Page 18: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Avoiding the Farm Config Wizard

• The Farm Config Wizard does some very bad things

• Wise SharePoint admins avoid it

• Use PowerShell to replicate its functionality

• Steps

• Managed accounts

• Web applications

• MySite host

• Service application pool

• State Service

• Usage Service

• The rest

Page 19: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Everyday tasks

• Add-SPShellAdmin

• Move-SPSite

• Enable Developer Dashboard

• Troubleshooting

• Master pages

• Get database sizes

Page 20: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Add-SPShellAdmin

• Necessary for unprivileged accounts, since you’re not logging in as the Farm account, right?

• Must specify databases to give access to

• Gives permissions to an account

• WSS_Admin_WPG on SharePoint servers

• SharePoint_Shell_Access role on database

• To run it account must have:

• Security_Admin role SQL instance

• db_owner role on database

• Local admin on SharePoint server

Page 21: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Move-SPSite

• Used to move Site Collections between content databases

• Everything ‘mergecontentdbs’ can do, this can do better

• Mostly done on the SQL side

• Databases must be attached to the same web application, and on the same SQL instance

• Works great to get rid of Content databases with GUIDs

Page 22: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

• Can be enabled with STSADM, but that’s just embarrassing

• More flexibility with PowerShell

$dash =

[Microsoft.SharePoint.Administration.SPWebService]::Conte

ntService.DeveloperDashboardSettings;

$dash.DisplayLevel = 'On';

$dash.TraceEnabled = $true;

$dash.Update()

Developer Dashboard

Page 23: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Get-SPLogEvent -StartTime (Get-Date).addminutes(-10) –Directory

e:\logs | Where-Object {$_.correlation -eq "dc07834b-9982-4eaf-

aacf-d62a6b398f87"}

Troubleshooting

• Use New-SPLogFile immediately before and right after recreating a problem

• Use Merge-SPLogFiles to collect trace logs from all servers in your farm

• Use Get-SPLogEvent to get events

• Can filter by a number of properties, like Correlation ID

• Can point at alternate directory

Page 24: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

$web = Get-SPWeb http://sharepoint

$web.CustomMasterUrl =

"/_catalogs/masterpage/nightandday.master"

$web.MasterUrl = "/_catalogs/masterpage/nightandday.master"

$web.Update()

Master Pages

• Can be used to set the master page

Page 25: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

RACKSPACE® HOSTING | WWW.RACKSPACE.COM

Get-SPDatabase | Sort-Object disksizerequired -desc | Format-

Table Name, @{Label ="Size in MB"; Expression =

{$_.disksizerequired/1mb}}

Get-SPDatabase | ForEach-Object {$db=0} {$db

+=$_.disksizerequired; $_.name + " - " +

$_.disksizerequired/1mb} {Write-Host "`nTotal Storage (in MB)

=" ("{0:n0}" -f ($db/1mb))}

Database Information

• Use Get-SPDatabase to get list of databases and their properties

Page 26: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

Links

• Todd doing this without Shane

• http://www.toddklindt.com/sizzle

• Zach Rosenfield’s blog

• http://sharepoint.microsoft.com/Blogs/zach

• Gary Lapointe’s blog

• http://blog.falchionconsulting.com/

• Document your farm with PowerShell

• http://technet.microsoft.com/en-us/library/ff645391.aspx

• PS Scripts

• http://get-spscripts.com/

Page 27: Introduction to Windows PowerShell for SharePoint Administrators August 2013... · 2013-08-16 · Introduction to Windows PowerShell for SharePoint Administrators Shane Young and

Things we referenced

• Determine database sizes in PowerShell

• http://www.toddklindt.com/SP2010DatabaseSize

• Remoting requirements for SharePoint 2010

• http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID=45

• Developer Dashboard

• http://www.toddklindt.com/devdashboard

• Master Pages

• http://www.toddklindt.com/SetSP2010MasterPage

• Use Move-SPSite

• http://www.toddklindt.com/blog/Lists/Posts/Post.aspx?ID=233

• SharePoint 2013 PowerShell Guide

• http://technet.microsoft.com/en-us/library/ff678226.aspx