My Developer blog

Welcome to my blog, I wanted a place that I could document and share all my development experiences and if it helps people on the way all the better. this is the beginning of the site but I have lots of ideas and will constantly add to it and hopefully blog about it on the way.

Everyday PowerShell commands for SharePoint peeps.

This will be a continuous kind of article where I will keep adding PowerShell commands as and when I use them…

Load the SharePoint Snap In as part of your scripts

Load a snap in for added functionality, supressing error info if the snap in is already loaded.

 Add-PSSnapin microsoft.SharePoint.powershell -ErrorAction SilentlyContinue 


Finding out more

Get a list of all SharePoint related commands

 Get-Command *-SP* 

Get information about any command

 Get-Help Get-SPSite -full 

Farm Commands

Get Farm object

 $Farm = Get-SPFarm 

List Alternative Access Mappings


List Servers in Farm


Web Applications(IIS Site) Commands

Get a single web application

 Get-SPWebApplication http://your.url 

Get all web applications in the Farm


Site Collection Commands

Get a specific site collection

 Get-SPSite http://your.url 

Get all site collections in a web application

 Get-SPSite -webapplication http://your.url -limit all 

Get all site collections in the Farm

 Get-SPSite -Limit all 

Get SiteCollections from a Web Application Object

 $webapp = get-spwebapplication http://your.url

Web Commands

Get a specific web

 Get-SPWeb http://your.url/sites/SiteCollections/yourweb 

Get all webs in a single site collection

 Get-SPWeb -site http://your.url/sites/SiteCollections 

Get all webs in a single site collection, from a site collection object

 $SITES = Get-SPSite -WebApplication http://your.url -Limit all
 foreach ($oneSite in $sites) {$OneSite.AllWebs } 

Get all webs in the farm

 $webApps = Get-SPWebApplication
 foreach ($webApps in $WebApps)
  	foreach ($site in $webApp.Sites)

Get User Information

Get a specific User

 $web = Get-SPWeb "http://your.url"
 $user $web.EnsureUser("domain\username")
 write-host $user.LoginName 

Working with Solutions/Packages

Install Solution

Install-SPSolution -Identity YourPackagedfile.wsp -GACDeployment 

Add Solution

Add-SPSolution -LiteralPath c:\locationOfYourfile.wsp 

Update Solution

Update-SPSolution YourPackagedfile.wsp -LiteralPath "c:\locationOfYourfile.wsp" -GACDeployment

Uninstall Solution

Uninstall-SPSolution -Identity YourPackagedfile.wsp

Enable Feature

Enable-SPFeature "YourFeature" -Url http://your.url -force

Disable Feature

Disable-SPFeature "YourFeature" -Url http://your.url -Confirm:$false

Uninstall Feature

Uninstall-SPFeature -Identity "YourFeature"

Importing - Exporting - Backing Up Commands

Exporting\Backup a site collection or subsite

stsadm -o export -url  http://your.url -filename SiteOrSubSiteName 


 Export-SPWeb http://your.url -Path "FileName.cmp" 


Import-SPWeb http://your.url -Path C:\Users\SP_Admin\FILENAME.cmp 
-UpdateVersions Overwrite 


stsadm -o import -url http://your.url -filename FILENAME.cmp -includeusersecurity 

Working with Application Services

To find an application pool

 Get-SPServiceApplicationPool | select Id, Name

To set up an Application Service

 New-SPServiceApplicationPool -Name AccessServices2013AppPool 
 -Account Domain\sp_account
 $serviceAppName = "Access Services 2013"
 $onPremAppPool = "AccessServices2013AppPool"
 $sqlServerName = "SQLDatabaseName"
 $ApplicationPool = Get-SPServiceApplicationPool -Identity $onPremPool

 New-SPAccessServiceApplication -Name $serviceAppName -ApplicationPool 
 $ApplicationPool -Default -DatabaseServer   $sqlServerName 

To remove an App

 $instances = Get-SPAppInstance -Web 
 $instance = $instances | where {$_.Title -eq ''}

 Uninstall-SPAppInstance -Identity $instance

Web Applications

To rename a web applcation

 $a=Get-SPWebApplication | where {$_.Name -match "Web application name"}
 $a.Name="New web application name"

Other Useful commands

The LifeSaver or headache depending on the results


Command to find out your certs or Ports

netsh http show sslcert > cert.txt
notepad cert.txt 

Get Content databases


To Test Outgoing email from SharePoint

$sd = new-object System.collections.specialized.stringdictionary
$sd.add("Subject","Test email!")
$web = get-spweb "http://your.url"
$body = "This is our body
We can use HTML code in it."   [Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web,$sd,$body)

To Enable Alerts

stsadm.exe -o setproperty -url http://your.url -pn alerts-enabled -pv true

Adding another AD domain Forest to your current setup to allow for the people picker to pickup new names

STSADM.exe -o setproperty -pn peoplepicker-searchadforests -pv "forest:oldDomain; forest:newDomain" -url http://your.url

Creating a Managed Path, with site and subsite using Powershell

This post is on how to create a Managed Path, with site and subsite using PowerShell.

Step by step guide

Creating a new web Application, Site and Subsite using PowerShell

How to create a new web application, with a site collection, and a site…

Step by step guide

Adding Mimetypes in Sharepoint

If you want to add .html files to your SharePoint pages

Step by step guide