Forum Discussion

Luis Duran's avatar
Luis Duran
Copper Contributor
Oct 25, 2018

I cannot get Set-PnPFileCheckedIn to work

Here is the part of the code that does the checkin for files in a folder

$folder = "/Documents" 

$filesInFolder = Get-PnPFolderItem -FolderSiteRelativeUrl $folder -ItemType File
foreach($file in $filesInFolder)
{
    if($file.Level -eq "Checkout") {
       $filePath = ($folder + "/" + $file.Name)
        Set-PnPFileCheckedIn -Url $filePath -CheckinType MajorCheckIn -Comment "Checked in by Script"
}

I keep getting the error:

Set-PnpFileCheckedIn : serverRelativeUrl

Parameter name: Specified value is not supported for the serverRelativeUrl parameter

 

I have tried every variation of the url I can think of :

"/Documents/test.txt"

"Documents/test.txt"

"/sites/testsite/Documents/test.txt"

etc...

 

I need to check in 60,000 documents that a user uploaded checked out and nobody can see them. They are in multiple folders. I thought that this would be an easy fix, but I have spent all day on it already!

1 Reply

  • Matt Weston's avatar
    Matt Weston
    Iron Contributor

    Hi Luis Duran I've just tried running your code and for me it works. My code looks like this:

     

    $folder = "/Shared Documents"
    $filesinfolder = Get-PnPFolderItem -FolderSiteRelativeUrl $folder

    foreach($file in $filesInFolder)
    {
    $filepath = "$($folder)/$($file.Name)"
    Set-PnPFileCheckedIn -Url $filePath -CheckinType MajorCheckIn -Comment "Checked in by Script"
    }

     

    I would suggest checking the version of the PnP PowerShell Commands that you're running:

    Get-Module

    My local version is 3.2.1810.0, so I'd suggest updating your PS modules if you're at an earlier version

     

    Update-Module SharePointPnPPowerShellOnline

     

    I hope that helps, if not please let me know and I'll have another look for you :)