Check In File in SharePoint using PowerShell

The example in this topic show how to use PowerShell to Check In File in SharePoint

  • # Provide credentials over here
  • $creds = (New-Object System.Management.Automation.PSCredential "<<UserName>>",(ConvertTo-SecureString "<<Password>>" -AsPlainText -Force))
  •  
  • # Provide URL of the Site over here
  • # If you do not wish to pass credentials hard coded then you can use: -Credentials (Get-Credential). This will prompt to enter credentials
  • Connect-PnPOnline -Url http://MyServer/sites/MySiteCollection -Credentials $creds
  •  
  • # Get Context
  • $clientContext = Get-PnPContext
  •  
  • # -Url: relative path of the file
  • # -AsListItem: Retrieves the file and returns it as a ListItem object
  • $ListItem = Get-PnPFile -Url "/Shared Documents/aatest.txt" -AsListItem
  •  
  • # Get the File object
  • $targetFile = $ListItem.File
  •  
  • $clientContext.Load($targetFile)
  •  
  • $clientContext.ExecuteQuery()
  •  
  • # First parameter is to enter the comment about the Check In action
  • # Second parameter is two pass the Type of Check In. Below are the options
  • # (1) MajorCheckIn - This value indicates increase in Major version of the file
  • # (2) MinorCheckIn - This value indicates increase in Minor version of the file
  • # (3) OverwriteCheckIn - Overwrite to avoid creating new version
  •  
  • $targetFile.CheckIn("Minor Check In Comment","MinorCheckIn")
  •  
  • $clientContext.ExecuteQuery()
  •  
  • Disconnect-PnPOnline 

Thank you for reading this article. This code was tested in SharePoint 2013


We value your feedback:

Page URL:

Name:

 

Email:

 
 

Feedback:

 

© 2019 Code SharePoint