Did you know that if you’re a SharePoint Site collection owner you cannot see all the pages created? A few days ago, I notice that I should have a certain number of pages on the Site Pages library (80 or something) but only a few appear for my user. You can verify how many files you have on the particular library on the Site contents of your site.
This happens because the page was created but nothing was been done with the page. Let’s give some example of how this can happen. You create a page on SharePoint but before adding any text or anything like that you just close the browser or navigate somewhere else. SharePoint will create a page with a random name that is saved for your user. This page will only be visible to your user, therefore, all the SharePoint Site collection owners will not see this file and this will create unnecessary information.
You can takeover this files following this steps
The script below allows you to take control of the same files using PowerShell rather than UI. In case that you are doing some more actions on the site via PowerShell.
$library = "Site Pages"
$siteUrl = "https://contoso.sharepoint.com/sites/demosite"
Connect-PnPOnline -Url $siteUrl -UseWebLogin
$context = Get-PnPContext
$list = Get-PnPList -Identity $library
# Load the list
$context.Load($list)
Invoke-PnPQuery
# Load the checked out files
$checkedOutFiles = $list.GetCheckedOutFiles()
$context.Load($checkedOutFiles)
Invoke-PnPQuery
foreach ($file in $checkedOutFiles) {
#Takeover the file
Write-Host ("{0} File TakeOver" -f $file.ServerRelativePath.DecodedUrl)
$file.TakeOverCheckOut()
Set-PnPFileCheckedIn -Url $file.ServerRelativePath.DecodedUrl
}
The post Take control of files created on SharePoint that are not published appeared first on SharePoint Tricks.
Original Post https://sharepoint-tricks.com/take-control-of-files-created-that-are-not-published-sharepoint/