PowerShell Script to check-in the Publishing Page in SharePoint 2013

Introduction

In this blog we will about check-in all checked out page in SharePoint 2013 using PowerShell method. We need to check-in many pages in our Site Collection for our development purpose.

For that I have created a small PowerShell script to work on this.

Steps

  1. Start your windows PowerShell on your computer.
  2. Right click and select Run as administrator option.
  3. Paste the below script on the PowerShell window and click the enter button.
  4. Check your SharePoint site page will be created successfully.

Code

  1. # Add the PowerShell Snapin      
  2. $snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}      
  3. if ($snapin -eq $null)       
  4. {       
  5.    Add-PSSnapin "Microsoft.SharePoint.Powershell"      
  6. }    
  7. # Get the siteURL    
  8. $spWeb = Get-SPWeb http://thegowtham.sharepoint.com/    
  9. # Enter the pages library name     
  10. $listName = "text"    
  11.  $list = $spWeb.Lists |? {$_.Title -eq $listName}    
  12.   foreach ($item in $list.Items)     
  13.   {    
  14.     $itemFile = $item.File    
  15.     # identify the all checked out file and do chekin using admin previlage     
  16.     if( $itemFile.CheckOutStatus -ne "None" )    
  17.     {     
  18.        $itemFile.CheckIn("Automatic CheckIn. (Administrator)")    
  19.     }    
  20.   }    
  21. $spWeb.Dispose()    

Run the script with the required administrator privilege.

To verify that, go the Pages Library and make sure that all pages are checked in.