PowerShell For SharePoint Admins PDF
PowerShell For SharePoint Admins PDF
Agenda
What is Windows PowerShell
Windows PowerShell basics
Windows PowerShell scripts for administrators
Compliments CMD
Extends STSADM
Uses XML & Objects
Built on the .NET Framework
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
DEMO
PowerShell Basics
PowerShell Scripts
Build scripts to easily execute through common
commands & tasks!
Can be developed and scheduled using Windows
Task Scheduler.
Register-ScheduledJob
PowerShell Scripts
Examples:
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.
ForEach-Object { }
DEMO
PowerShell Scripts
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
Everyday tasks
Add-SPShellAdmin
Move-SPSite
Enable Developer Dashboard
Troubleshooting
Master pages
Get database sizes
Add-SPShellAdmin
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
Developer Dashboard
$dash =
[Microsoft.SharePoint.Administration.SPWebService]::Conte
ntService.DeveloperDashboardSettings;
$dash.DisplayLevel = 'On';
$dash.TraceEnabled = $true;
$dash.Update()
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
Master Pages
Can be used to set the master page
Database Information
Use Get-SPDatabase to get list of databases and
their properties
Get-SPDatabase | Sort-Object disksizerequired -desc | FormatTable 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))}
Links
Todd doing this without Shane
http://www.toddklindt.com/sizzle
Zach Rosenfields blog
http://sharepoint.microsoft.com/Blogs/zach
Gary Lapointes 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/
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