Skip to content

Instantly share code, notes, and snippets.

@jonschoning
Created August 16, 2011 14:36
Show Gist options
  • Save jonschoning/1149225 to your computer and use it in GitHub Desktop.
Save jonschoning/1149225 to your computer and use it in GitHub Desktop.
SP2010_PS_Examples.ps1
# %CommonProgramFiles%\Microsoft Shared\Web Server Extensions\14\Config\PowerShell\Registration\SharePoint.ps1
# $Host.Runspace.ThreadOptions = "ReuseThread"
# Add-PsSnapin Microsoft.SharePoint.PowerShell
#DEMO: Get-Command, Get-Member
#Display the help for the Get-Command cmdlet
help get-command
#Get a listing of all the SharePoint cmdlets
gcm -pssnapin Microsoft.SharePoint.PowerShell
#Store a listing of all the SharePoint cmdlet definitions in a text file sorted by noun
gcm -pssnapin Microsoft.SharePoint.PowerShell | sort noun | select Definition | Set-Content c:\cmds.txt
#Get just the SPService related cmdlets
gcm -noun SPService*
#We can also use multiple wildcards
gcm *SPService*
#Return just the syntax of a cmdlet
gcm Get-SPServiceApplicationPool -syntax
#Display the help for the Get-SPServiceApplicationPool cmdlet
help Get-SPServiceApplicationPool
#Get a listing of all the application pools
Get-SPServiceApplicationPool
#See all the available methods and properties
Get-SPServiceApplicationPool | gm
#Return back the actual ID shown in IIS
Get-SPServiceApplicationPool | select Id, Name
#DEMO: PowerShell Threading
#Retrieve the current thread settings
$host.Runspace.ThreadOptions
#Create a utility function to quickly get the current thread Id
function Get-ThreadId { [Threading.Thread]::CurrentThread.ManagedThreadId }
#Get the thread ID three times using three lines
Get-ThreadId
Get-ThreadId
Get-ThreadId
#Get the thread ID three times in one line
Get-ThreadId;Get-ThreadId;Get-ThreadId
#DEMO: Maintenance cmdlets
#Show the help for Get-SPLogEvent
help Get-SPLogEvent
#Get all events for a Correlation ID
Get-SPLogEvent | where {$_.Correlation -eq "fb72b45e-2ef2-43c8-971b-030c360633b"}
#Test a content database
Test-SPContentDatabase SharePoint_Content_Portal1 -ShowRowCounts
#Enable the developer dashboard
$dash = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings
$dash.DisplayLevel = "OnDemand"
$dash.TraceEnabled = $true
$dash.Update()
#DEMO: Reporting
#Get Usage for a set of site collections—shows a collection for usage
Get-SPSite | Select URL, Usage
#Use a calculate property to “reach inside” the Usage property to get a specific value
Get-SPSite | Select URL, @{Expression={$_.Usage.Storage}}
#Make it cleaner with titles and formatting
Get-SPSite | Select URL, @{Name="Storage"; Expression={"{0:N2} GB" -f ($_.Usage.Storage/1GB)}}
#Then do something with the data! This new "object" is still pipelineable and actionable (here with GridView)
Get-SPSite | Select URL, @{Name="Storage"; Expression={"{0:N2} GB" -f ($_.Usage.Storage/1GB)}}, @{Name="Quota"; Expression={"{0:N2} GB" -f ($_.Quota.StorageMaximumLevel/1GB)} } | Out-GridView -Title "Sites w/Usage"
#Get all the installed features
Get-SPFeature
#Get all the features installed for a specific scope
Get-SPFeature | Where { $_.Scope –eq "Web" }
#Get information about a specific feature
Get-SPFeature ContentTypeHub | select *
#Get all enabled features for a specific scope
Get-SPFeature -Site http://portal
#Launch the AuditReport.ps1 script file in the editor
powershell_ise .\AuditReport.ps1
#Display all users and their permissions for http://portal
. .\AuditReport.ps1 -includeitems:$false -url http://portal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment