introduction to windows powershell for sharepoint administrators

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

Upload: others

Post on 03-Feb-2022

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Windows PowerShell for SharePoint Administrators

Introduction to Windows PowerShell for SharePoint Administrators

Shane Young and Todd Klindt

SharePoint Nerds

Rackspace

Page 2: Introduction to Windows PowerShell for SharePoint Administrators

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

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

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

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

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

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

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

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

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

DEMO

PowerShell Basics

Page 12: Introduction to Windows PowerShell for SharePoint Administrators

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

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

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

DEMO

PowerShell Scripts

Page 16: Introduction to Windows PowerShell for SharePoint Administrators

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

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

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

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

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

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

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

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

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

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

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

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