Kwizcom Forms

30+ PowerShell SharePoint Examples

PoweShell SharePoint examples

In this PowerShell SharePoint tutorial, we will discuss a few PowerShell SharePoint examples. This PowerShell SharePoint explains, how to undo check out a page using PowerShell Script, Change Page Layout using PowerShell Script in SharePoint, how to Extract wsp from SharePoint Farm Solutions using PowerShell,

Also, we will see how to use PowerShell script to empty SharePoint Recycle Bins and how to collect ULS logs for specific CorrelationID in SharePoint 2016/2013 using PowerShell.

SharePoint deveopment training course

We will see how to Export Site details into Excel file in SharePoint 2016/2013, PowerShell to get installed SharePoint Version Number.

If you are new to PowerShell SharePoint, then you can read an article: Working with PowerShell in SharePoint Online/2016/2013.

Any PowerShell script, you can write, debug and test script using Windows PowerShell ISE and Visual Studio Code.

SharePoint 2016 Tutorial Contents

SharePoint: Undo check out a page using PowerShell Script

This example explains how to undo check out a page using PowerShell script in SharePoint 2016/2013/2010. Recently we face one issue in one of the migration project. Some pages were coming to check out by some people and when we try to do a check-in, overwrite check-out or discard check out, nothing worked for us.

Below is the PowerShell script you can use to UndoCheckOut using PowerShell for SharePoint 2013/2016. You can pass the particular page URL to do undo checkout.

Add-PSSnapin Microsoft.SharePoint.PowerShell
$spWeb = Get-SPWeb(“https://SiteURL/”)
$spFile = $spWeb.GetFile(“https://SiteURL/Pages/MyTestpage.aspx”)
$spFile.UndoCheckOut()
$spFile.CheckIn(“Checkin Done”[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
$spFile.Update()
$spWeb.Dispose()

SharePoint 2013/2016 Change Page Layout using PowerShell Script

In this example, we will discuss how we can change a page layout using a PowerShell script. We can use PowerShell to change page layout in SharePoint 2013/2016/2010.

PowerShell script to change page layout of default.aspx page in SharePoint 2013/2016

Below is the PowerShell script to change the page layout of default.aspx page in a SharePoint 2013/2016 site or subsite.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”
$spWeb = Get-SPWeb(“https://SiteURL”)

$spFile = $spWeb.GetFile(“https://SiteURL/Pages/default.aspx”)
$spFile.CheckOut(“Online”,$null)
$spFile.Properties[“PublishingPageLayout”] = “/SiteURL/_catalogs/masterpage/WelcomeLinks.aspx”
$spFile.Update()
$spFile.CheckIn(“Update page layout via PowerShell”,[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
$spWeb.Dispose()

Change page layout of all the pages using PowerShell in SharePoint 2013/2016

If you want to change the page layout of all the pages then you can use the below PowerShell.

$spWeb = Get-SPWeb(“https://SiteURL”)
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
$pSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($spWeb.Site);

$siteLayouts = $pSite.GetPageLayouts($false)
$myLayout = $siteLayouts[“/_catalogs/masterpage/WelcomeLinks.aspx”]
#$myLayout
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = “Scope=’RecursiveAll'”

$pages = $pWeb.GetPublishingPages($query)

foreach ($page in $pages)
{
if ($page.ContentType.Name -eq “Folder”)
{
continue
}

$page.Layout = $myLayout
$page.update()
$page.ListItem.File.Publish(“”)
$page.ListItem.File.Approve(“”)
}
$spWeb.Dispose()

This way you can change page layout in SharePoint 2013/2016 using PowerShell.

Extract wsp from SharePoint Farm Solutions using PowerShell

Below is the PowerShell script to Extract wsp from SharePoint Farm Solutions in SharePoint 2016/2013.

$farm = Get-SPFarm
$file = $farm.Solutions.Item(“solutionname.wsp”).SolutionFile
$file.SaveAs(“E:\Backup\solutionname.wsp”)

The above PowerShell script will extract wsp from farm solutions in SharePoint 2016/2013 using PowerShell.

PowerShell script to empty SharePoint Recycle Bins

Now, we will see PowerShell script to empty SharePoint Recycle Bins. Below is the PowerShell command to delete Recycle Bin using PowerShell.

$WebApp=get-spwebapplication “Enter URL”
foreach ($SPSite in $webApp.Sites)
{
#get the collection of webs
foreach($SPWeb in $SPSite.AllWebs)
{
#Empty the 1st Stage Recycle bin items PERMENANTLY
#$SPWeb.RecycleBin.DeleteAll();
#Send the 1st Stage Recycle bin items to 2nd Stage
$SPWeb.RecycleBin.MoveAllToSecondStage();

write-host “End-User Recycle Bin Items Deleted for:”
write-host $SPWeb.title “:” $SPWeb.URL “`n”
}
#Empty SharePoint site collection recycle bin (2nd Stage Recycle bin) or Admin Recycle bin
$SPSite.RecycleBin.DeleteAll();
write-host “Administrator Recycle bin Items Deleted for:” $SPSite.RootWeb.title “`n”
}

PowerShell Command to collect ULS logs for specific CorrelationID in SharePoint 2016/2013

Now, we will discuss how we can collect ULS logs for specific CorrelationID using PowerShell. Below is the PowerShell command to collect ULS logs for specific CorrelationID:

get-splogevent -starttime (get-date).addminutes(-20) | where-object { $_.correlation -eq “b66db71a-3257-4470-adf9-5c01dc59ecb3? } | fl message > c:\errors.txt

PowerShell Script to Export Site into Excel file

Below is the PowerShell script to retrieve site details using PowerShell in SharePoint 2016/2013.

Get-SPSite “http://sharepoint.company.com/sales/” | Get-SPWeb -Limit All | Select Title, Url | Export-Csv -NoTypeInformation -Path “c:\sites.csv”

PowerShell to get installed SharePoint Version Number

Now, we will see how to get installed SharePoint version number using PowerShell in SharePoint 2016/2013.

Get-Spfarm | Select BuildVersion

Change SharePoint Site Title and description using PowerShell

Below is the PowerShell script to change the SharePoint 2013/2016 site title and description using PowerShell script. By using PowerShell you can change the title and description easily.

$Web= Get-SPWeb "http://SiteURL"
$Web.Title = "My New Portal"
$Web.Description = "This is our new portal"
$web.Update()

After you execute the PowerShell script, the site title and description will get changed.

Attach event receivers to SharePoint list using PowerShell

This SharePoint PowerShell example explains, how to attach an event receiver to SharePoint 2013/2010 list using PowerShell. Here I will show how we can attach an event receiver to a SharePoint list in SharePoint 2010/2013.

PS > $spWeb = Get-SPWeb http://siteurl
PS > $spList = $spWeb.Lists[“Tasks”]
PS > $spEvent.Name = “My Event”
PS > $spEvent.Type = “ItemAdded”
PS > $spEvent.Synchronization = “Asynchronous”
PS > $spEvent.SequenceNumber = 3000
PS > $spEvent.Assembly = “My.SharePoint.Event, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a8b0a959bb9389c6”
PS > $spEvent.Class = “My.SharePoint.Event.PowerShellEventReceiver”
PS > $spEvent.Update()
PS > $spWeb.Dispose()

The above code explains, how to attach an event receiver to SharePoint 2010 list using PowerShell.

Change SharePoint list Settings using PowerShell

We will see now how we can change SharePoint list settings using PowerShell. Through PowerShell, you can change SharePoint list title, description, whether a version will be enabled or not etc.

#Get the site and list objects

$web = Get-SPWeb http://entersiteurl
$list = $web.Lists[“Shared Documents”] // Enter the name of list.

#Now enter the changes what you want

$list.Title = “Enter Title Name”
$list.Description = “Enter Description”
$list.OnQuickLaunch = $true
$list.EnableModeration = $true //Enable content Approval
$list.EnableVersioning = $true //Enable the versioning

#Update the list and dispose of the web object

$list.Update()
$web.Dispose()

Show hide Workflow History list using PowerShell in SharePoint 2013/2010

Now we will see how to show hide workflow history list using PowerShell in SharePoint 2016/2013/2010. Sometimes you will not get the “Workflow History” list which appears to be hidden.

So below is the PowerShell command, once you will execute this the “Workflow History” list will appear.

$web = Get-SPWeb “http://WebURL”
$list = $web.Lists[“Workflow History”]
$list.Hidden = $false
$list.Update()

Get System Accounts using PowerShell

Now we will see how to get all system accounts using PowerShell in SharePoint 2010. PowerShell is very much improved as compared to STSADM.

SPProcessAccount helps us to get all the system accounts like LocalSystem account, LocalService account, and NetworkService account.

Get-SPProcessAccount:
This command will retrieve all of the above accounts.
But if you want to retrieve individually then we have to follow below commands:

LocalSystem account:
Get-SPProcessAccount –LocalSystem

LocalService account:
Get-SPProcessAccount -LocalService

NetworkService account:
Get-SPProcessAccount –NetworkService

PowerShell Command to Create a new Web Application in SharePoint 2016/2013/2010

Now we will discuss how to create a web application in SharePoint 2010/2013/2016 using PowerShell. SPWebApplication is responsible for creating a new web application in PowerShell.

New-SPWebApplication –applicationpool <Application pool name> -name <Web app name> -applicationpoolaccount <service account for the application pool> -port <port number>

Example:
New-SPWebApplication –applicationpool SharePoint-80 -name SharePoint-80 -applicationpoolaccount SP2010\Administrator -port 80

PowerShell Command to Create a New Site Collection (Top Level Site)

Now, we will discuss how can we create a new site collection using PowerShell in SharePoint 2010/2013/20166

New-SPSite is responsible for creating a new site collection.

New-SPSite –url <full url of new site collection>
-name <name of new site collection>
-owneralias <site collection administrator>
-template <site collection template to use>

Example:
New-SPSite –url http://enjoysharepoint/ -name Home -owneralias SP2010\Administrator -template STS#0

PowerShell Command to Create a New Sub Site in SharePoint

Now, we will discuss how to create a new subsite in SharePoint using PowerShell. SPWeb is responsible for creating a subsite.

New-SPWeb –url <full url of new site> -name <name of new sub site> -template <site template to use>

Example:
New-SPWeb –url http://enjoysharepoint/TestSubSite -name “Test Sub Site” -template STS#0

Below are few PowerShell command:

  • Get-command : To see PowerShell commands in the window.
  • Get-command SP : Show all commands that contain word SP.
  • Get-command -SP > c:\spcommands .txt: Will save all commands to a text file, those commands contains the word SP.
  • get-help : Give some suggestion. When we need help.
  • Get-SPWebApplication : Information about the web application. It will display the list of all web applications and its display name and URL of the web application.
  • Get-SPSite : Returns lists of all the site collectios’ URL.
  • Get-SPDatabase : Show list of all SharePoint Database Name, ID and Type.
  • Set-SPSite -Identity http://Site-Collection-URL -MaxSize 500MB: Limits the size of the site collection

Backup and restore site collection using PowerShell in SharePoint 2010/2013/2016

Now we will discuss how to backup and restore a site collection using PowerShell in SharePoint 2010/2013/2016.

Backup a SharePoint Site Collection with PowerShell command

Backup-SPSite -Identity http://myserver -Path “c:\backup\file.bak”

Restore a SharePoint Site Collection with PowerShell command

To restore site collection you’ll use the following command. Use –Force if you want to overwrite the existing site collection

Restore-SPSite -Identity http://myserver -Path “c:\backup\file.bak”

Download a wsp file from SharePoint using PowerShell

We can able to download a particular wsp file from SharePoint central admin using PowerShell. There is no direct approach to download a wsp file from Central Administration. You will only see the option to Retract a solution file.

Below is the PowerShell command to download a solution (wsp) file:

$farm = Get-SPFarm
$file = $farm.Solutions.Item(“MyTest.wsp”).SolutionFile
$file.SaveAs(“c:\MyTest.wsp”)

Remember to run the above PowerShell command you need to be a member of the Farm Administrators group and have permission to the configuration database.

Change SharePoint site logo using PowerShell

Now we will see, how we can change the SharePoint 2010/2013/2016 site logo using PowerShell.

SharePoint 2010/2013 site default logo comes from the _layouts/images/ folder.

If you want to put your new logo then you can put your logo to a folder where you have read access. Also, you can put your logo to the Assets Library also.

Below is the PowerShell script to change site logo in SharePoint

$web = Get-SPWeb “http://SiteURL”
$web.SiteLogoUrl = “http://Path of the image file”
$web.SiteLogoDescription = “EnjoySharePoint.com company Logo”
$web.Update()

After this refresh the SharePoint page, the new logo should appear.

Delete an application pool using PowerShell in SharePoint

Here we will discuss how we can delete an application pool using PowerShell in SharePoint.

PowerShell is the best way to remove an application pool for SharePoint. Sometimes you may need to remove unused application pool accounts.

Open SharePoint management PowerShell, Make sure you are running as administrator mode.

Run the below command which will display all the application pools.

Get-SPServiceApplicationPool

Then run the below command to get the particular Application Pool.

Get-SPServiceApplicationPool -Identity <Name of the application pool>

Now we can to delete whatever the application pool we want.

Remove-SPServiceApplicationPool ‘Name of the Application Pool’

The above PowerShell command will delete the application Pool.

Approve master page using PowerShell in SharePoint 2010/2013/2016

Now we will see how to approve a modified master page using PowerShell in SharePoint 2010/2013/2016.

Sometimes SharePoint gives some error when you try to commit the master page which you have edited using SharePoint Designer 2013/2010. In that case, you can use the PowerShell to approve the master page.

The following PowerShell script will help you to approve the master page in SharePoint.

Open SharePoint 2010/2013/2016 management PowerShell, Make sure you are running as administrator mode.

$SPWeb = Get-SPWeb “http://SiteURL”
$file = $SPWeb.GetFile(“_catalogs/masterpage/MyCustomMaster.master”)
$file.CheckIn(“”)
$file.Publish()

The above PowerShell script will approve master page in SharePoint.

Prevent delete of SharePoint list using PowerShell

We can also restrict the user to delete a particular SharePoint list using PowerShell in SharePoint 2013/2016. We can prevent delete option in SharePoint list by using PowerShell.

$web = Get-SPWeb “http://SiteURL””
$list = $web.Lists[“My Custom List”]
$List.AllowDeletion=$false
$List.Update()

Once you execute this PowerShell code, you can not delete the list.

PowerShell commands for scheduling user profile timer job in SharePoint

We can use PowerShell command for scheduling user profile timer job in SharePoint 2013/2016.

Powershell command to schedule user profile timer job

Get-SPTimerJob is used to return timer jobs.

Get-SPTimerJob returns all the timer jobs with Name, Schedule, and Last Run.

Get-SPTimerJob UserProfile_ProfileImportJob | Set-SPTimerJob -Schedule “weekly between sun 12:00:00 and wed 12:00:00” | Start-SPTimerJob

Schedule:
Specifies the schedule for running the timer job.

The type must be a valid SharePoint Timer service (SPTimer) schedule in the form of any one of the following schedules:

Every 5 minutes between 0 and 59
Hourly between 0 and 59
Daily at 15:00:00
Weekly between Fri 22:00:00 and Sun 06:00:00
Monthly at 15 15:00:00
Yearly at Jan 1 15:00:00

PowerShell commands for SharePoint database

This SharePoint tutorial explains various PowerShell commands for SharePoint database. We will see how to retrieve all databases, get particular web application, create a new content database, etc. Below are PowerShell Commands to see all databases.

Get-SPDatabase

The above command will return all databases.

If you want to retrieve a particular database then follow below command:
Get-SPDatabase-Identity

The cmdlet to get all the web applications:
Get-SPWebApplication

PowerShell Command to create new content database:

New-SPContentDatabase –Name ContentDBName –WebApplication “Web Application URL”

PowerShell Cmdlet to retrieve all content database for a particular web application:

Get-SPContentDatabase –WebApplication “Web Application URL”

Get-SPContentDatabase –WebApplication “http://bsahoo3:2600/”

PowerShell Cmdlets to Attach a Content Database to a Web Application:

Mount-SPContentDatabase –Name “ContentDBName” –WebApplication “Web Application URL”

PowerShell Cmdlet to Delete a Content Database:

Remove-SPContentDatabase “ContentDBName”

PowerShell Cmdlet to Create a New Configuration Database:

New-SPConfigurationDatabase –DatabaseName NewConfigurationDBName –DatabaseServer “Database Server name”

PowerShell Cmdlet to Delete a Configuration Database:

Remove-SPConfigurationDatabase

This command will delete the current configuration database.

PowerShell Cmdlet to take backup of a configuration database:

Backup-SPConfigurationDatabase –Directory C:\DatabaseBackUp

PowerShell Cmdlet to take restore of a configuration database:

Restore-SPFarm –Directory C:\DatabaseBackUp

PowerShell Cmdlet to Back Up the SharePoint Farm:

Backup-SPFarm –BackupMethod Full –Directory C:\FarmBackup

Full means it will take backup of the entire farm.

PowerShell Cmdlet to Restore the SharePoint Farm:

Restore-SPFarm –Directory C:\FarmBackup –RestoreMethod Overwrite

PowerShell Cmdlet to Back Up a Site Collection:

Backup-SPSite –Identity “http://Site Collection URL”–Path C:\SiteCollectionBackup\MySiteCollection.bak

PowerShell Cmdlet to Restore a Site Collection

Restore-SPSite –Identity “http://Site Collection URL”–Path C:\SiteCollectionBackup\MySiteCollection.bak –Force

Force will overrite the existing site collection.

PowerShell to know site created date SharePoint 2013/2016/2010

Below are the PowerShell commands to know the site created date in SharePoint 2013/2016/2010.

PowerShell command to get all site collections created date

Below is the PowerShell command to get all sites collections created date in SharePoint.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”
Get-SPSite -Limit All | select Url, {$_.RootWeb.Created}

PowerShell command which will give Sites and Subsites created in the last 30 days

Below is the PowerShell command or script which will give sites and subsites created in last 30 days.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”
$Today = [DateTime]::Today
$Before30Days = $Today.AddDays(-30)
Get-SPSite -Limit All | where {$_.RootWeb.Created -ge $Before30Days -And $_.RootWeb.Created -lt $Today} |
select Url, {$_.RootWeb.Created}

PowerShell command which will return sites created Today

Below is the PowerShell command which will return sites which are created today in SharePoint 2013.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”
$Today = [DateTime]::Today
Get-SPSite -Limit All | where {$_.RootWeb.Created -eq $Today} |
select Url, {$_.RootWeb.Created}

PowerShell command which will return sites and subsites created date for a Particular site collection

Below is the PowerShell command which will return sites and subsites created date for a particular site collection.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”
$site = get-spsite https://SiteCollectionURL/
$webs = $site.allwebs
foreach ($w in $webs){Write-Host $w.title ” is created on ” $w.created}

How to set a custom page as homepage using PowerShell in SharePoint 2010/2013

We can set my newly created custom page in my SharePoint site as the home page. It’s possible to use a custom page as a home page. You can set it in multiple ways: If you have enabled the Publishing features on your site, or your site was created from a Publishing template, then you can just go to Site Actions, Site Settings and click Welcome Page, then select a page.

You can open the site in SharePoint Designer, right-click any .ASPX page, and select Set as Home Page.

If you’re a developer, you can set the home page by using the code. See the MSDN page “SPFolder.WelcomePage property” for more information.

If you’re a SharePoint administrator, you can use a Windows PowerShell script to select a master page:

$site = Get-SPSite http://yourserver/sites/yoursite
$web = $site.RootWeb
(or $web = $site.OpenWeb(“yoursubsite”)
$folder = $web.RootFolder
$folder.WelcomePage = “SitePages/home.aspx”
(or $folder.WelcomePage = “default.aspx”)
(or $folder.WelcomePage = “Shared%20Documents/mycustomwebpartpage.aspx”)
$folder.update()
$web.Dispose()
$site.Dispose()

Get SharePoint feature details from Feature ID or Display Name using PowerShell

Now, we will see how we to get SharePoint feature details based on FeatureID and also by using Feature DisplayName using PowerShell in SharePoint 2013/2016.

Sometimes you may need to know about the feature details based on the feature Id in SharePoint

PowerShell command to get feature details based on SharePoint feature id

Below is the PowerShell command to get the feature details based on feature id in SharePoint 2013/2016.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Get-SPFeature -Limit ALL | Where-Object {$_.id -eq "22a9ef51-737b-4ff2-9346-694633fe4416"}
Get SharePoint 2013 feature details from Feature ID or Display Name using PowerShell
Get SharePoint 2013 feature details from Feature ID or Display Name using PowerShell

PowerShell command to get feature details based on feature display name in SharePoint 2013/2016

Below is the PowerShell command to get the SharePoint feature details based on the feature display name.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Get-SPFeature -Limit ALL | Where-Object {$_.DisplayName -eq "Publishing"}

Retrieve all site collections under particular content databases using PowerShell

This example, we will see how to retrieve all site collections under a particular content database programmatically using PowerShell in SharePoint 2013/2016.

Here I have a content database name as: WSS_Content_808ab8b0aa0b4298bd1e626628caa80d

Write the below command to get all the site collections presented in the content database:

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
Get-SPSite -ContentDatabase "WSS_Content_808ab8b0aa0b4298bd1e626628caa80d"

If you want to retrieve in csv or text format then you can write the below:

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
Get-SPSite -ContentDatabase "WSS_Content_808ab8b0aa0b4298bd1e626628caa80d"> E:\AllSites.txt

Or

Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
Get-SPSite -ContentDatabase "WSS_Content_808ab8b0aa0b4298bd1e626628caa80d"> E:\AllSites.csv

Once you run the above command you can see all site collections like below:

Retrieve all site collections under particular content databases using PowerShell

Insert bulk items to SharePoint Online list using PowerShell

This PowerShell SharePoint example, we will discuss how to insert bulk items to a SharePoint Online list using PowerShell.

Here I have a list as “Laptop” and by using PowerShell we will insert 5000 items to the SharePoint Online list.

Add-Type -Path 'C:\Users\Admin\Desktop\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\Users\Admin\Desktop\Microsoft.SharePoint.Client.Runtime.dll'

$SiteURL = "https://<tenantname>.sharepoint.com/sites/LaptopCompany/"
$listName="Laptop"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$securePassword=ConvertTo-SecureString "MyPassword@123" -AsPlainText -Force
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("anjaline@<tenantname>.onmicrosoft.com", $securePassword)
$web = $ctx.Web
$list = $web.get_lists().getByTitle($listName)
for ($i=1; $i -le 5001; $i++)
{
$itemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$listItem = $list.addItem($itemCreateInfo)
$listItem.set_item('Title', 'Laptop Request')
$listItem.set_item('LaptopName', 'Hp')
$listItem.set_item('Price', '20000')
$listItem.update();
$ctx.Load($listItem)
$ctx.ExecuteQuery()
}

Once you run the above PowerShell cmdlets, it will insert 5000 items to the SharePoint Online list.

Get a list of pages using a particular page layout using PowerShell in SharePoint 2013

This SharePoint PowerShell example, we will see, how to get a list of pages that are using a particular page layout in SharePoint 2013 using PowerShell.

Recently while working on a moss 2007 to SharePoint 2013 migration project we got a scenario where we need to find out the page names from a document library which is using a particular page layout in SharePoint 2013/2016.

Below is the PowerShell script to get the list of pages using a particular page layout using PowerShell in SharePoint 2013.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
$site = get-SPSite http://win-pfcp2dgt8di/sites/EnjoySharePoint/
$web = $site.RootWeb
$pweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pPages = $pWeb.GetPublishingPages();
$pLayouts ="ErrorLayout.aspx" #$pweb.GetAvailablePageLayouts()
foreach ($pPage in $pPages)
{
if ($pPage.Layout.Name -eq $pLayouts)
{
write-host $pPage.Title
}
}

This PowerShell example helps to learn, how to get a list of pages using a particular page layout using PowerShell in SharePoint 2013/2016.

You may like following PowerShell SharePoint tutorials:

This PowerShell SharePoint explains, how can we undo check out a page using PowerShell Script, How to change Page Layout using PowerShell Script in SharePoint.

Also, we will see how to Extract wsp from SharePoint Farm Solutions using PowerShell and PowerShell script to empty SharePoint Recycle Bins.

We will also see how to collect ULS logs for specific CorrelationID in SharePoint 2016/2013 using PowerShell. PowerShell Script to Export Site into Excel file, PowerShell to get installed SharePoint Version Number.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →