Cmdlets I use most often

I love the power of PowerShell. And I use it a lot to do stuff, it is much easier and faster than using CA. And I find myself googling Microsoft or other pages over and over for the same commands, because I simply cannot remember the parameters and it is faster to just google it. So I will add them here now, for my own convenience! Copy and paste away 😉


Install-SPFeature -path “MySiteLayouts”
Enable-SPFeature -Identity MySiteLayouts -Url https://sps
Uninstall-SPFeature “MySiteLayouts”
Disable-SPFeature “MySiteLayouts” -Url https://sps


Add-SPSolution E:SP_install_filesWebpartsWebPart.wsp
Install-SPSolution –Identity WebPart.wsp –WebApplication https://sps -GACDeployment

Delete a list by GUID

$w = Get-SPWeb “https://sps

Create a site using custom template

Get custom template ID
$url = “https://sps
$site= new-Object Microsoft.SharePoint.SPSite($url )
$loc= [System.Int32]::Parse(1033)
$templates= $site.GetWebTemplates($loc)
foreach ($child in $templates){ write-host $child.Name ”  ” $child.Title }

Create a new site with the custom template id
$newWeb = New-SPWeb -Url https://sps/newsite -Name “New Site Name”

Delete database

$del = get-spdatabase “9437afae-953a-4373-81dc-88186e0ec30e”

Get all site features and save them in a txt file

Get-SPFeature | Sort -Property Scope,DisplayName | FT -GroupBy Scope DisplayName,Id > E:outputAllInstalledFeatures.txt

Create new site and import cmp

New-SPWeb -url “https://sps/docs/
Import-SpWeb -identity “https://sps/documents/” -path “E:importsdocs.cmp” -IncludeUserSecurity

Import photo thumbnails from AD

Note: To be able to import the photos you need to first add an import of those in the User Profile Service Application. Go to User Properties, scroll down to “Pictures”, scroll down to the list of AD fields and select “thumbnailphoto”. Click on Import and add it. Save and do a full user profile import synchronization. Then you can run this command (I have this in Scheduled Tasks, it runs every night):

Update-SPProfilePhotoStore -CreateThumbnailsForImportedPhotos 1 -MySiteHostLocation https://mysites

Create State Service Application

New-SPStateServiceDatabase –Name “StateService” | New-SPStateServiceApplication –Name “State Service” | New-SPStateServiceApplicationProxy –DefaultProxyGroup

Start a Service Application

Often the WSS_Usage service application is not started by default when you install a new server.

$UP = Get-SPServiceApplicationProxy | where {$_.ID -eq “e31e3a1b-3c46-42d0-ad78-822cb48daafc”}

The GUID is the service application that is not started.

0 0 votes
Rate this article!
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments