Download presentation
Presentation is loading. Please wait.
1
The Administrator’s Best Friend
PowerShell The Administrator’s Best Friend Brian Caauwe – Senior Consultant April 14, 2012
2
Session Agenda What you need to know Top 10 Cmdlets Top 10 Scripts
3
Who am I? Brian Caauwe SharePoint Consultant & Speaker Certifications
Blog: Certifications MCITP: SP Administrator 2010 MCPD: SP Developer 2010
4
Minnesota SharePoint User Group
2nd Wednesday of the Month 9:00 – 11:30 AM SharePoint resources and links Meeting Schedule Past User Group Presentations This Presentation Next Meeting – 5/9 TBD
5
Quick Poll SharePoint Version Work Roles 2007 – WSS, MOSS
2010 – SPF, Server, FAST Work Roles SharePoint Administrator SharePoint Developer Business User Other
6
What you need to know
7
What you need to know You won’t learn by books or sessions
Find YOUR practical applications
8
What you need to know Run “As Administrator”
Management Shell Run “As Administrator” Uses powershell.exe under Windows\system32 Registers Microsoft.SharePoint.PowerShell snap-in via script C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\ Registration\sharepoint.ps1 Sets Execution Policy to RemoteSigned
9
What you need to know Object Model Microsoft.SharePoint namespace
Server Architecture SPFarm SPWebApplication SPContentDatabase Site Architecture SPSite SPWeb SPList SPListItem MSDN Resource
10
What you need to know Call PowerShell from Windows\system32
Scheduled Tasks Call PowerShell from Windows\system32 Register Microsoft.SharePoint.Powershell snap-in -psconsolefile “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL \Registration\psconsole.psc1” Call Script -command “E:\PowerShell\Set-ScriptName.ps1” Logging
11
What you need to know Memory Leakage Disposable Objects
$web.Dispose() $site.Dispose() SPAssignment – Garbage Collector Global Start-SPAssignment –Global Get-SPSite -Limit All | Get-SPWeb | Select Url, WebTemplate, WebTemplateId | Format-Table -AutoSize Stop-SPAssignment -Global Scoped $w = Get-SPWebApplication $siteScope = Start-SPAssignment foreach ($site in ($siteScope | Get-SPSite -Limit All –WebApplication $)) { $webScope = Start-SPAssignment foreach ($web in ($webScope | Get-SPWeb -Limit All -Site $site)) ## Do Something } Stop-SPAssignment $webScope Stop-SPAssignment $siteScope
12
What you need to know Remote Scripting Crazy setup
Run Commands on SharePoint servers Enable-PSRemoting –force Enable-WSManCredSSP –role Server –force Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024 Run Commands on local machine Enable-PSRemoting -force Enable-WSManCredSSP –role Client –DelegateComputer “*.domain.com or COMPUTERNAME” –force Shared SPModule (\\servername\spmodule) Zach Rosenfields’s Blog Store Credentials in a variable $cred = Get-Credential Load Modules $env:PSModulePath = \\servername\spmodule; + $env:PSModulePath Import-Module SPModule.misc Import-Module SPModule.setup
13
What you need to know Other Assemblies User Profile Managed Metadata
What you don’t get Other Assemblies IIS (WebAdministration) SQL Exchange User Profile Microsoft.Office.Server.UserProfiles Managed Metadata Microsoft.SharePoint.Taxonomy
14
Top 10 Cmdlets
15
Top 10 Cmdlets Tools for the toolbox Some SharePoint, Some NOT
SharePoint requires 2010
16
Top 10 Cmdlets How to Use Examples Get-Command | Get-Help
Built in help EVERYWHERE Start with what you know to find what you don’t Examples Get-Command *-SPFeature* Get-Help Backup-SPSite -Examples
17
Top 10 Cmdlets How to use Example
Get-SPWebApplication | Get-SPSite | Get-SPWeb How to use Main Cmdlets you will use Limit parameter SPSite and SPWeb are disposable Example $w = Get-SPWebApplication $site = Get-SPSite $site | Get-SPWeb -Limit All
18
Top 10 Cmdlets How to use Example Get-SPServer | Get-SPServiceInstance
Maintain services on server Get current server with environment variable Start-SPServiceInstance may need other configuration Example $server = Get-SPServer $env:COMPUTERNAME $svc = Get-SPServiceInstance -Server $server | ?{$_.TypeName -eq “Excel Calculation Services”} if ($svc.Status –eq “Disabled”){ Start-SPServiceInstance }
19
Top 10 Cmdlets How to use Example Get-SPServiceApplication
Maintain properties of service applications Pipe to query on TypeName Example $svcApp = Get-SPServiceApplication | ?{$_.TypeName -eq “User Profile Service Application”} $svcApp.NetBIOSDomainNamesEnabled = $true $svcApp.Update()
20
Top 10 Cmdlets How to use Example New-SPLogFile
Great for troubleshooting Creates new log file on that server Example New-SPLogFile
21
Top 10 Cmdlets How to use Example Merge-SPLogFile
Merges last hour of logs across farm Can consume CorrelationId and other filters Example Merge-SPLogFile –Path “C:\Debug\error.log” –Correlation 470a4ec2-985d-43be-a14e-176eb1c39672
22
Top 10 Cmdlets How to use Example Get-SPLogEvent
Gets ALL log events (no time filter) Single server Pipe to query and use -StartTime parameter Example $guid = “470a4ec2-985d-43be-a14e-176eb1c39672” Get-SPLogEvent –StartTime (Get-Date).AddHours(-1) | ?{$_.Correlation –eq $guid} | Format-List Timestamp, Category, Message | Out-File “c:\Debug\debug.log”
23
Top 10 Cmdlets How to use Example
Add-SPSolution | Get-SPSolution | Install-SPSolution How to use Add farm solution to solution store Automated deployments Example Add-SPSolution –LiteralPath “C:\Solutions\spcmis.wsp” $sol = Get-SPSolution | ?{$_.Name –eq “spcmis.wsp”} $sol | Install-SPSolution –GACDeployment -AllWebApplications
24
Top 10 Cmdlets How to use Example Out-File Write to the file
Nice for logging on scheduled tasks Use -Append parameter Example $msg = “This is what I want to send to the file” $path = “logging.log” $currentTime = Get-Date –UFormat “%H:%M:%S” $msg = $currentTime + “ :: DEB :: “ + $msg $msg | Out-File $path -append
25
Top 10 Cmdlets How to use Example Write-Host | Read-Host
Write-Host used to display status to the screen Use ForegroundColor for color coding Read-Host used to get user input Example $url = Read-Host “What is the web application URL” $w = Get-SPWebApplication $url Write-Host -ForegroundColor Green $w.Url
26
Top 10 Scripts
27
Top 10 Scripts My favorites to find information in a crazy world
28
Top 10 Scripts Get-ErrorLog.ps1 What it uses When to use it
Merge-SPLogFile Get-SPLogEvent When to use it When you get a correlation ID How to use it Choose to query farm or current server
29
Top 10 Scripts Get-SiteStorageInfo.ps1 What it uses When to use it
Start-SPAssignment / Stop-SPAssignment Get-SPWebApplication / Get-SPSite When to use it Get storage size and quota How to use it Run as scheduled task or on demand
30
Top 10 Scripts Get-WebInfo.ps1 What it uses When to use it
Start-SPAssignment / Stop-SPAssignment Get-SPWebApplication / Get-SPSite / Get-SPWeb When to use it Get web properties (Url, Template, Author, Last Modified) How to use it Run as scheduled task or on demand
31
Top 10 Scripts Get-WorkflowInfo.ps1 What it uses When to use it
Start-SPAssignment / Stop-SPAssignment Get-SPWebApplication / Get-SPSite / Get-SPWeb SPList / SPContentType / SPWorkflowAssociation When to use it Get workflow properties (SPD, Author, Running Instances) How to use it Run as scheduled task or on demand
32
Top 10 Scripts Get-VersionInfo.ps1 What it uses When to use it
Start-SPAssignment / Stop-SPAssignment Get-SPWebApplication / Get-SPSite / Get-SPWeb SPList When to use it Get version properties (Item Count, Versioning, Limits) How to use it Run as scheduled task or on demand
33
Top 10 Scripts Warmup-Farm.ps1 What it uses When to use it
System.Net.CredentialCache / WebClient Get-SPWebApplication / Get-SPSite Get-Content When to use it Keep system connections “hot” How to use it Run as scheduled task or on demand Reference Kirk Hofer Martin Laukkanen
34
Top 10 Scripts Set-UserProfileImages.ps1 What it uses When to use it
Microsoft.Office.Server.UserProfiles Start-Transcript Update-SPProfilePhotoStore When to use it Centrally managed photos to push into SharePoint How to use it Run as scheduled task or on demand
35
Top 10 Scripts What it uses When to use it How to use it Reference
Invoke-AlertFixup.ps1 What it uses Get-SPWeb / SPSite SPAlert When to use it Fix up alerts after changing web application url or site collection url How to use it Invoke-AlertFixup -site “ -oldurl “ Reference TechNet
36
Top 10 Scripts What it uses When to use it How to use it
Check-Loopback.ps1 What it uses Get-Item New-ItemProperty When to use it Need to check for registry value and create if needed How to use it Use as part of build scripts other server admin
37
Top 10 Scripts What it uses When to use it How to use it Reference
Get-AccountCreds.ps1 What it uses Microsoft.Web.Administration When to use it Used to recover application pool credentials How to use it Run on demand, requires application pool name Reference Raymond Mitchell (IWKid)
38
DEMO
39
References Brian’s Blog Windows PowerShell for SharePoint 2010
Windows PowerShell for SharePoint 2010 Script References Invoke-AlertFixup Raymond Mitchell’s Blog Kirk Hofer’s Blog Martin Laukkanen
40
Q & A
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.