40 Useful PowerShell SharePoint Commands

Learn some PowerShell SharePoint Commands in this tutorial. In any organization, they are mostly using the PowerShell command for all operations in SharePoint. Here I have explained few commands which are mainly required for all SharePoint developer.

At A Glance - Here's what we'll cover: show

How to use PowerShell in SharePoint

If you are new to PowerShell, then you should know how to use PowerShell in SharePoint.

  • SharePoint Online management shell: Check out this complete tutorial, if you want to work with SharePoint Online using PowerShell. It will explain, how to download, install and use SharePoint Online management shell to work with SharePoint Online.
  • How to use PowerShell in SharePoint: Check out this article if you want to know how to use PowerShell in SharePoint on-premises versions like SharePoint 2013/2016/2019.

Below are the PowerShell SharePoint examples which we are going to discuss here. The commands will work in SharePoint On-premises versions like SharePoint 2019/2016/2013/2010.

For all the PowerShell SharePoint commands, I am using Windows PowerShell ISE or Visual Studio Code to run the PowerShell commands or scripts.

PowerShell SharePoint Commands

Now, let use see around 50 useful PowerShell SharePoint commands.

powershell sharepoint commands
powershell sharepoint commands

1. Create site collection using PowerShell in SharePoint

Below is the PowerShell SharePoint command or script to create a site collection using PowerShell in SharePoint. You may also like below SharePoint site collection tutorial:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Configuration Variables
$SiteCollURL = "https://www.enjoysharepoint.com/sites/RajDemo"
$SiteName = "Welcome To Enjo SharePoint"
$SiteOwner = "HQAdmin\rswain"
$SiteTemplate = "STS#0"  #Team Site Template
 
#Create new Site Collection
New-SPSite -URL $SiteCollURL -OwnerAlias $SiteOwner -Template $SiteTemplate -Name $SiteName

2. PowerShell create a site collection in a specific content database in SharePoint

Below is the PowerShell command to create a site collection in a specific content database in SharePoint. You may like the following SharePoint content database tutorials:

New-SPSite -Name "Welcome To Enjo SharePoint" -ContentDatabase SP2013_demo_Content -url https://www.enjoysharepoint.com/sites/RajDemo `-OwnerAlias "HQAdmin\rswain" -Template "STS#1"

3. Delete site collection PowerShell

Below is the PowerShell SharePoint Command to delete site collection PowerShell in SharePoint.

Remove-SPSite -Identity "https://www.enjoysharepoint.com/sites/RajDemo" 

4. Force delete SharePoint site collection using PowerShell

Below is the PowerShell SharePoint Command to force delete SharePoint site collection using PowerShell script.

$Site = Get-SPSite https://www.enjoysharepoint.com/sites/RajDem
$SiteContentDB = $site.ContentDatabase
$SiteContentDB.ForceDeleteSite($Site.Id, $false, $false)

5. PowerShell delete all site collections in a web application in SharePoint

Below is the PowerShell SharePoint command which will delete all site collections in a web application in SharePoint 2013/2016/2019.

$WebAppURL="https://www.enjoysharepoint.com/sites/RajDemo"
Get-SPWebApplication $WebAppURL | Get-SPSite -Limit ALL | Remove-SPSite -Confirm:$false

6. Bulk delete site collections with PowerShell

Below the PowerShell script which will delete site collections in bulk in SharePoint.

Get-SPSite "https://www.enjoysharepoint.com/sites/RajDemo" -Limit ALL | Remove-SPSite -Confirm:$false

7. PowerShell Get site information in SharePoint

Below is the PowerShell SharePoint command to get site information in SharePoint 2013/2016.

Get-SPSite 'https://www.enjoysharepoint.com/sites/RajDemo' | Get-SPWeb -Limit All | Select Title

8. PowerShell get all site collections in a SharePoint farm

Below is the PowerShell SharePoint command, which will get all site collections in a SharePoint farm.

Get-SPWebApplication | Get-SPSite -Limit All | Format-Table -Property URL,ContentDatabase

9. Get all subsites from Site Collection using PowerShell

Below is the PowerShell script to get all subsites from SharePoint Site collection using PowerShell.

Get-SPWebApplication https://www.enjoysharepoint.com/sites/RajDemo | Get-SPSite -Limit All | Get-SPWeb -Limit All | Select Title, URL | 
Export-CSV C:\SharePoint_Sites_Report.csv -NoTypeInformation

10. Get all subsites of a subsite using PowerShell in SharePoint

Below is the PowerShell SharePoint commands to get all subsites of a subsite using PowerShell in SharePoint 2013/2016/2019.

param ( [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] [String]$StartWeb, [Boolean]$IncludeStartWeb = $true )
 
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
$subsites = ((Get-SPWeb $StartWeb).Site).allwebs | ?{$_.url -like "$StartWeb*"}
 
foreach($subsite in $subsites) { Write-Host $subsite.url }

11. SharePoint PowerShell backup content database

Below is the PowerShell command to take backup of content database in SharePoint.

Backup-SPFarm -Directory <BackupFolder> -BackupMethod {Full | Differential} -Item <ContentDatabaseName> [-Verbose]

12. SharePoint PowerShell restore a content database

Below is the PowerShell SharePoint command which will restore SharePoint content database in SharePoint 2013/2016.

Get-SPContentDatabase -ConnectAsUnattachedDatabase  -DatabaseName <DatabaseName> -DatabaseServer <DatabaseServer>

13. Backup site using PowerShell SharePoint 2013/2016/2019

Below is the PowerShell command to backup site in SharePoint 2013.

Backup-SPSite https://www.enjoysharepoint.com/sites/RajDemo -Path C:\Backup\site_name.bak -UseSqlSnapshot

14. Restore site using PowerShell in SharePoint 2013/2016/2019

Below is the PowerShell command to restore site in SharePoint 2013/2016 using PowerShell.

Restore-SPSite https://www.enjoysharepoint.com/sites/RajDemo -Path C:\Backup\site_name.bak -Force -DatabaseServer SQLBE1 -DatabaseName SQLDB1

15. Get all lists in a SharePoint Site using PowerShell

Below is the PowerShell SharePoint commands to get all lists in a SharePoint site using PowerShell.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  
$Site = Get-SPSite "https://www.enjoysharepoint.com/sites/RajDemo"
# get the all sub sites of site
$SubSites = $Site.AllWebs
$SubSites | ForEach-Object { 
$Site = $_
# get all lists from site
$lists = $Site.Lists | Where-Object { $_.BaseType -eq 'GenericList' }
$lists | ForEach-Object {                 
    New-Object -TypeName PSObject -Property @{
              ListName = $_.Title
              SiteName = $Site.Title
              SiteUrl = $Site.Url
}}}

16. Get all libraries in a SharePoint Site using PowerShell

Below is the PowerShell script which will retrieve all libraries in a SharePoint site.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
$Site = Get-SPSite "https://www.enjoysharepoint.com/sites/RajDemo"
# get the all sub sites of site
$SubSites = $Site.AllWebs
$SubSites | ForEach-Object { 
$Site = $_
# get all document Libraries from site
$lists = $Site.Lists | Where-Object { $_.BaseType -eq 'DocumentLibrary' }
$lists | ForEach-Object {                                     
    New-Object -TypeName PSObject -Property @{
              LibraryName = $_.Title
              SiteName = $Site.Title
              SiteUrl = $Site.Url
}}}

17. Create a List using PowerShell in SharePoint

Below is the PowerShell script to create a list in SharePoint using PowerShell.

Add-PSSnapin 'Microsoft.SharePoint.PowerShell' -ErrorAction SilentlyContinue            
$SPweb = Get-SPWeb -Identity 'https://www.enjoysharepoint.com/sites/RajDemo'            
$ListTemplate = $SPweb.ListTemplates['Custom List']            
$SPweb.Lists.Add('SharePoint', 'List creation demo using PowerShell' , $ListTemplate)

18. Delete List in SharePoint using PowerShell

Below is the PowerShell command to delete list in SharePoint 2013/2016/2019.

Add-PSSnapin 'Microsoft.SharePoint.PowerShell' -ErrorAction SilentlyContinue            
$SPweb = Get-SPWeb -Identity 'https://www.enjoysharepoint.com/sites/RajDemo'            
$list = $SPweb.Lists['SharePoint']            
$item1 = $list.Items            
$item1[0].Delete()

19. PowerShell add item to SharePoint list

Below is the PowerShell command to add item to SharePoint 2013/2016 list.

Add-PSSnapin 'Microsoft.SharePoint.PowerShell' -ErrorAction SilentlyContinue            
$SPweb = Get-SPWeb -Identity 'https://www.enjoysharepoint.com/sites/RajDemo'            
$list = $SPweb.Lists['SharePoint']            
$item1 = $list.Items.Add()            
$item1['Title'] = 'Chendrayan'            
$item1.update()

20. Get list and libraries having versioning enabled in SharePoint using PowerShell

Below is the PowerShell script which will retrieve lists and libraries having versioning enabled and the list is not hidden in SharePoint using PowerShell.

Get-SPWeb https://www.enjoysharepoint.com/sites/RajDemo |
   Select -ExpandProperty Lists |
   Where { -not $_.hidden -and
           $_.EnableVersioning -eq $true} |
   Select ParentWebUrl, title

21. Delete Item in a specific list in SharePoint using PowerShell

Below is the PowerShell SharePoint command to delete items from a SharePoint list.

System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

$site = new-object Microsoft.SharePoint.SPSite("https://www.enjoysharepoint.com/sites/RajDemo")
$relweburl = ”/rajtest”
$web = $site.openweb($relweburl)

$list = $web.Lists[“RajList”]

$listItems = $list.Items
$listItemsTotal = $listItems.Count

for ($item=$listItemsTotal-1;$item -ge 0; $item–)
{

Write-Host(“DELETED: ” )
$listItems[$item].Delete()
}
}

22. SharePoint PowerShell bulk delete list items

Below is the PowerShell script to delete list items in bulk in SharePoint.

Add-PSSnapin Microsoft.SharePoint.Powershell -ea SilentlyContinue
$web = get-spweb "https://www.enjoysharepoint.com/sites/RajDemo"
$list = $web.lists["List Title"]
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"
$query.RowLimit = 1000
$query.ViewFields = "<FieldRef Name='ID'/>"
$query.ViewFieldsOnly = $true
do
{
   $listItems = $list.GetItems($query)
   $query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
   foreach($item in $listItems)
   {
     Write-Host "Deleting Item - $($item.Id)"
     $list.GetItemById($item.Id).delete()
   }
}
while ($query.ListItemCollectionPosition -ne $null) 

23. Activate features using PowerShell in SharePoint

Below is the PowerShell command to activate feature in SharePoint. You may like the following SharePoint features tutorials:

Enable-SPFeature –Identity Reporting –url https://www.enjoysharepoint.com/sites/RajDemo

24. Deactivate features using PowerShell in SharePoint

Below is the PowerShell command to deactivate features using PowerShell in SharePoint.

Disable-SPFeature –Identity Reporting –url https://www.enjoysharepoint.com/sites/RajDemo

25. Get all features using PowerShell in SharePoint

Below is the PowerShell command to get all the features in SharePoint 2013/2016.

Get-SPFeature –Site https://www.enjoysharepoint.com/sites/RajDemo

26. Add user to a SharePoint group using PowerShell

Below is the PowerShell command to add user to a SharePoint group.

#Get the Web
$web=Get-SPWeb "https://www.enjoysharepoint.com/sites/RajDemo"
#Get the SharePoint Group
$Group= $web.Groups["DHLOwners"]
$userName = "SPADmin\rswain"
 
#Add User to the site collection
$user = $web.EnsureUser($UserName)
 
#Add User to the Group
$group.AddUser($user)

27. Remove user from SharePoint group using PowerShell

Below is the PowerShell SharePoint Command to remove users from SharePoint group.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
Function RemoveUser-FromGroup($SiteURL, $GroupName, $UserAccount)
{
 try
    {
     $ErrorActionPreference = "Stop"
   
     #Get the Web
     $web=Get-SPWeb $SiteURL
     
     #Get the User to Remove
     $User  = Get-SPUser -Identity $UserAccount -Web $web
 
     #Get the Group by its name
     $Group = $Web.sitegroups | Where-Object {$_.Name -eq $GroupName}
     if($Group -ne $null)
     {
         #sharepoint powershell delete user from group
         $Group.RemoveUser($User)
         Write-Host "$($User) Removed from the Group: $($GroupName)"
     }
   }
 catch
    {
           #Write error message on screen and to a LOG file
           write-host $_.Exception.Message
    }
 finally
    {
           $ErrorActionPreference = "Continue"
    }
}
 
#Call the function to remove user from SharePoint group
RemoveUser-FromGroup "https://www.enjoysharepoint.com/sites/RajDemo" "DHL Owners" "SPADMIN\rswain"

28. Remove user from all SharePoint groups using PowerShell

Below is the PowerShell command to remove users from all SharePoint groups using PowerShell in SharePoint 2013/2016.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
Function RemoveUser-FromAllGroups($SiteURL, $UserAccount)
{
     #Get the Web
     $web=Get-SPWeb $SiteURL
     
     #Get the User to Remove
     $User  = $Web.EnsureUser($UserAccount)
 
     #Iterate through all Groups
     foreach($Group in $Web.Groups)
     {
         $GroupUser = $Group.Users | where {$_.UserLogin -eq $User.UserLogin}
         #Check if user member of the group
         if($GroupUser -ne $null)
         {
            #remove user from sharepoint group using powershell
            $Group.RemoveUser($User)
            Write-Host "$($User) Removed from the Group: $($Group)"
         }
     }
 }
 
 #Call the function to remove a user from all groups in the site 
 RemoveUser-FromAllGroups "https://www.enjoysharepoint.com/sites/RajDemo" "SPADMIN\rswain"

29. Create a SharePoint group using PowerShell

Below is the PowerShell command or script to create a SharePoint group using PowerShell in SharePoint 2013/2016.

Add-PSSnapin Microsoft.SharePoint.PowerShell –ErrorAction SilentlyContinue
 
#Custom Function to Create new SharePoint Group
function Create-SPGroup
{ 
    param ($SiteURL, $GroupName, $PermissionLevel, $GroupDescription) 
 
    try
    {
        #Get the Web
        $web = Get-SPWeb -Identity $SiteURL
         
        if($web -ne $null)
        {
            #Check if Group Exists already
            if ($web.SiteGroups[$GroupName] -ne $null) 
            { 
                write-Host "Group $GroupName exists Already!" -ForegroundColor Red
            } 
            else 
            { 
                #Create SharePoint Group
                $Web.SiteGroups.Add($GroupName, $web.Site.Owner, $web.Site.Owner, $GroupDescription) 
                #Get the newly created group and assign permission to it
                $Group = $web.SiteGroups[$groupName] 
                $roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group) 
                $roleDefinition = $web.Site.RootWeb.RoleDefinitions[$permissionLevel] 
                $roleAssignment.RoleDefinitionBindings.Add($roleDefinition) 
                $web.RoleAssignments.Add($roleAssignment) 
                $web.Update() 
 
                write-Host "Group: $GroupName created successfully!" -ForegroundColor Green
            } 
  
            $web.Dispose()
        }
    }
    catch [System.Exception]
    {
        write-host $_.Exception.ToString() -ForegroundColor Red
    }
}
 
#Call the function to create Sharepoint group
Create-SPGroup "https://www.enjoysharepoint.com/sites/RajDemo" "My Powershell Group"

30. Delete a SharePoint group using PowerShell

Below is the PowerShell SharePoint command to delete a SharePoint group using PowerShell in SharePoint 2013/2016. You may like following SharePoint group tutorials:

Add-PSSnapin “Microsoft.SharePoint.PowerShell”
#Get web
$spWeb = Get-SPWeb "https://www.enjoysharepoint.com/sites/RajDem";
#Your group name
$GroupName="My SharePoint Group"

if($spWeb.SiteGroups[$GroupName] -ne $null)
{
$spWeb.SiteGroups.Remove($GroupName)
$spWeb.Update()
Write-Host “Group Deleted!”
}
else
{
Write-Host “Group doesn’t Exists!”
}

31. Get all SharePoint users using PowerShell in SharePoint 2013/2016

Below is the PowerShell SharePoint command to get all users from SharePoint group using PowerShell in SharePoint 2013/2016.

function GetSPAllSPUsers($SiteCollectionURL,$SPListName) 
{ 
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null 
    $site = new-object Microsoft.SharePoint.SPSite($SiteCollectionURL)     
    $web = $site.openweb() 
    $list = $web.Lists[$SPListName] 
    $siteCollUsers = $web.SiteUsers 
     
    foreach($user in $siteCollUsers) 
        { 
            Write-Host " ------------------------------------- " 
            Write-Host "Site Collection URL:", $SiteCollectionURL 
            if($list.DoesUserHavePermissions([Microsoft.SharePoint.SPBasePermissions]::ViewListItems,$user) -eq $true) 
                { 
                    Write-Host "User : ", $user.LoginName 
                    Write-Host "Assigned Permissions : ", $list.GetUserEffectivePermissions($user.LoginName) 
                }             
            Write-Host " ------------------------------------- "         
        } 
     
        $web.Dispose() 
        $site.Dispose() 
 } 

32. Get all groups in SharePoint using PowerShell

Below is the PowerShell command to get all groups in SharePoint using PowerShell.

$web = Get-SPWeb $webUrl;
$groups = $web.AssociatedGroups;

33. Change Site collection URL using PowerShell in SharePoint

Below is the PowerShell SharePoint command to change the site collection URL in SharePoint 2013/2016 using PowerShell. Also, read 3 Different ways to Change Site Collection URL in SharePoint 2013/2016 using PowerShell.

$site = Get-SPSite https://www.enjoysharepoint.com/sites/RajDem
$site.Rename("https://www.enjoysharepoint.com/sites/RajDemo1")

34. Change site collection Title and Description using PowerShell SharePoint 2013/2016

Below is the PowerShell SharePoint command to change the SharePoint site collection title and description.

function Using-Culture (
   [System.Globalization.CultureInfo]   $culture = (throw "USAGE: Using-Culture -Culture culture -Script {…}"),
   [ScriptBlock] $script = (throw "USAGE: Using-Culture -Culture culture -Script {…}"))
   {
     $OldCulture = [Threading.Thread]::CurrentThread.CurrentCulture
     $OldUICulture = [Threading.Thread]::CurrentThread.CurrentUICulture
         try {
                 [Threading.Thread]::CurrentThread.CurrentCulture = $culture
                 [Threading.Thread]::CurrentThread.CurrentUICulture = $culture
                 Invoke-Command $script
         }
         finally {
                 [Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
                 [Threading.Thread]::CurrentThread.CurrentUICulture = $OldUICulture
         }
}

$web = Get-SPWeb "https://www.enjoysharepoint.com/sites/RajDem"
$newTitle = "My new Title"
$newDesc = "My new Description"

# de-DE = German - Germany ; en-US = English - United States
Using-Culture de-DE { $web.Title=$newTitle; $web.Description=$newDesc; $web.Update() }

35. SharePoint PowerShell copy list items to another list

The below PowerShell command is to copy list items to another list using PowerShell in SharePoint 2013/2016.

$WebURL = "https://www.enjoysharepoint.com/sites/RajDem"
$SourceListName = "Source SharePoint"
$TargetListName= "Destination SharePoint"
 
#Get Objects
$web = Get-SPWeb $WebURL
$SourceList = $web.Lists[$SourceListName]
$TargetList = $web.Lists[$TargetListName]
 
#Get all source items
$SourceColumns = $sourceList.Fields
$SourceItems = $SourceList.GetItems();
 
#Iterate through each item and add to target list
Foreach($SourceItem in $SourceItems)
{
    $TargetItem = $TargetList.AddItem()
    Foreach($column in $SourceColumns)
    {
        if($column.ReadOnlyField -eq $False -and $column.InternalName -ne "Attachments")
        {
             $TargetItem[$($column.InternalName)] = $sourceItem[$($column.InternalName)];
        }
    }
   $TargetItem.Update();
}

36. Create a folder under a library in SharePoint using PowerShell

Below is the PowerShell SharePoint command to create a folder under a library in SharePoint 2013/2016. Below are also different ways to create a folder in SharePoint:

$webUrl = "https://www.enjoysharepoint.com/sites/RajDem"
$listName = "My Parent List"
$numberFoldersToCreate = 4000;
$folderNamePrefix = "folder";
 
# Open web and library
$web = Get-SPWeb $webUrl
$list = $web.Lists[$listName]
 
# Create desired number of subfolders
for($i=1; $i -le $numberFoldersToCreate; $i++)
{
$folder = $list.AddItem("", [Microsoft.SharePoint.SPFileSystemObjectType]::Folder, "$folderNamePrefix$i")
$folder.Update()
write-host $i
}
 
#Dispose web
$web.Dispose()

37. Change SharePoint authentication from classic mode to claims based mode using PowerShell

Let us see, how to change SharePoint authentication from classic mode to claims based mode in SharePoint using PowerShell. I will show how to change SharePoint authentication from classic mode to claims based PowerShell.

Recently I migrated the site from SharePoint 2013 to SharePoint 2016 and I faced some problems in authentication type in the targeted SharePoint server.

So after few RND, I got to know the solution to fix this issue. I missed to change the authentication type in targeted server. I executed the below Powershell script to achieve it.

Change SharePoint authentication from classic mode to claims based PowerShell

Below is the PowerShell script to change SharePoint authentication from classic mode to claims mode using PowerShell.

You can write, debug, test the PowerShell script using visual studio code or using windows PowerShell ISE.

$WebAppName = "http://hqRajdev16"
$wa = get-SPWebApplication $WebAppName
$wa.UseClaimsAuthentication = $true
$wa.Update()
$account = "TestAccount\Rajkiran"
$account = (New-SPClaimsPrincipal -identity $account -identitytype 1).ToEncodedString()
$wa = get-SPWebApplication $WebAppName
$zp = $wa.ZonePolicies("Default")
$p = $zp.Add($account,"PSPolicy")
$fc=$wa.PolicyRoles.GetSpecialRole("FullControl")
$p.PolicyRoleBindings.Add($fc)
$wa.Update()
$wa.MigrateUsers($true)
$wa.ProvisionGlobally()

When you execute this command, a confirmation message will appear on the screen. Type Y for confirmation.

After the command executed successfully, check the authentication provider from the SharePoint Central Administration, it will show “claims based authentication

38. Get Service Applications using PowerShell in SharePoint

Let us see, how to get all service applications using PowerShell in SharePoint 2019/2016/2013.

Service applications have been introduced in SharePoint 2013. Few service applications are: Search service application, Business Data Connectivity Serice, App Management Service, etc.

We can use PowerShell to create, configure and manage these service applications in SharePoint 2013/2016/2019.

We can use PowerShell to get all the available service applications in SharePoint environment. We can use the Windows PowerShell ISE or Visual studio code, to run the below command which will give all the service applications in SharePoint.

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue

GET-SPServiceApplication | Format-Table {$_.DisplayName}

Once you run the above command it will display the service application list like below:

$_.DisplayName
————–
Access Services 2010
Secure Store Service
PowerPoint Conversion Service Application
State Service
Workflow Service Application
Project Server Service Application
PerformancePoint Service Application
Visio Graphics Service
Managed Metadata Service
App Management Service
Security Token Service Application
Machine Translation Service
Application Discovery and Load Balancer Service Application
Usage and Health data collection
Subscription Settings Service
Search Administration Web Service for Search Service Application
Word Automation Services
User Profile Service Application
Business Data Connectivity Service
Access Services
Search Service Application

You can see the result it will appear like below:

get service application powershell sharepoint 2013
Get Service Applications using PowerShell in SharePoint

This is how to get all services applications using PowerShell in SharePoint 2013/2016/2019.

38. How to Change SharePoint master page using PowerShell

Let us see how to change SharePoint master page using PowerShell. Here I will show, how we can set a custom master page as default master page in SharePoint 2013 site.

SharePoint 2013 has two new default master page:

  • Seattle.master
  • oslo.master

The difference between Seattle.master and oslo.master is that if you use Oslo. master, the top navigation pane is replaced with the left navigation pane, and the sidebar on the left disappears.

Meaning that normally in the left navigation Home, Documents, Recent, Site Contents links usually appear. When you apply Oslo. master these links will appear in the top navigation pane. And there will be no links in the left sidebar.

Here I have developed a custom master page in SharePoint 2013 and I will set that custom master page as the default master page.

Below is the PowerShell command to set master page in SharePoint 2013, which we can run using Windows PowerShell ISE on the SharePoint server.

$web = Get-SPWeb http://win-pfcp2dgt8di/sites/EnjoySharePoint
$web.CustomMasterUrl = “/_catalogs/masterpage/mycustom.master”
$web.MasterUrl = “/_catalogs/masterpage/mycustom.master”
$web.Update()

This is how to set master page in SharePoint 2013 using PowerShell.

These are some PowerShell SharePoint command to work site, list, library, groups, etc. in SharePoint and I will keep adding more examples..

  • Thank you for the article and information!

    I’ve often wondered, from only the client-side, for SP2016 on-prem, is it possible to use PowerShell commands as a Site Collections admin without having access to the SharePoint Servers? That is, remote capability to use PowerShell?

  • >