Domanda

I have a problem with thousands of files not being checked in after upload to one of our site collections. I can't open the list of files with no version through the UI because of the exceeded treshold.

I have written a PowerShell script to check for CheckedOut files and check them in, however it looks like those files without checked in version are not visible from my admin account (I am the site collection administrator) even through PowerShell. I am using Get-PnPListItem cmdlet.

I have all the accesses including admin center etc, but I'm unable to find and check in those files. There's no knowledge/access to the account that uploaded the files.

Is there any way to get them?

Thanks a lot

È stato utile?

Soluzione

You might need to take ownership of the file before you can checkin. Please try below powershell script.

$web = Get-SPWeb "http://url_of-your-site"
$list = $web.Lists["NameOfDocumentLibrary"]

$files = $list.CheckedOutFiles

foreach($cf in $files)
{
    $file.TakeOverCheckOut() #Take Ownership

    $itemId = $file.ListItemId
    $item = $list.GetItemById($itemId)
    $newFile = $item.File
    $newFile.CheckIn("Checkin Comments")

    # If the library has minor major version enabled
    # $newFile.Publish("")
}

Update: The above script works for SharePoint 2013. The below code performs the same using CSOM and works for SharePoint Online.

$currentDir = (Split-Path -Parent $MyInvocation.MyCommand.Path)
$packagesPath = "Path to CSOM Nuget Package/library"

#Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
Add-Type -Path ($packagesPath + "/Microsoft.SharePoint.Client.dll")
Add-Type -Path ($packagesPath + "/Microsoft.SharePoint.Client.Runtime.dll")

[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;

$userName = Read-Host -Prompt 'Enter your email address'
$pwd = Read-Host -Prompt 'Enter your password' -AsSecureString

$context = New-Object Microsoft.SharePoint.Client.ClientContext("URL of the site")

$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $pwd)


$web = $context.Web;
$list = $web.Lists.GetByTitle("Name of Documnet Library")
$files = $list.GetCheckedOutFiles()
$user = $web.CurrentUser;

$context.Load($list);
$context.Load($user);
$context.Load($files);
$context.ExecuteQuery();


foreach($file in $files)
{
    if($file.CheckedOutById -ne $user.Id){
        $file.TakeOverCheckOut()
        $context.ExecuteQuery()

        $fileUrl = [string]::Concat($list.ParentWebUrl, $file.ServerRelativePath.DecodedUrl.Replace($list.ParentWebUrl, ""))
        $newFile = $web.GetFileByServerRelativeUrl($fileUrl)
        $newFile.Checkin("", 1)
        $context.ExecuteQuery()
    }
}

Altri suggerimenti

you might need to create a view on the document library in order to see fewer files in the view, otherwise SP will likely display no files. Go in via the Doc Library Settings>Create View>apply a filter e.g. show only files created today or in the last month. You should be able to see a filtered selection of files.

You might also want to try copying files to a new document library, in order to get under the 5,000 item limit. You'll find administering the document library easier once you are under the limit. Try going via the Site Settings>Content and Structure to copy or move the files to a new doc library. (n.b. there is a difference between copy or move - I remember something about one method preserving the version history of the files, I don't know if you need to keep version history or not?).

Another thing you can do is access the Manage Files Which Have No Checked in Version in the Document Library Settings menu - I know you've mentioned this in the title of your question, but nothing in the body of your question - it could be that this is unavailable to you due to there being too many files saved in a single Document Library. But once you've copied files elsewhere and are under 5,000, this should become available to you.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top