I tried to delete custom content type from Pages library but got an exception "content type is still in use". The I get to know that files should also be deleted from "Manage files which have no checked in version" in order to delete content type from Pages library.

How I can perform this step using powershell, any code hint can help me?

  • You would need to follow the same process as the UI, take ownership of them so they are checked out to you, then delete them. – Eric Alexander Mar 2 '16 at 13:20

$web = get-spweb http://yourwebsite
$list = $web.Lists["your list"]

#get checked out files that have no major version
$checkedOutFiles = $list.CheckedOutFiles | ?{$_.Versions.Count -eq 0}

write-host ("Found "  + $checkedOutFiles.Count + " file(s)!")

foreach($file in $checkedOutFiles)
    write-host ("Parsing file: " + $file.LeafName)
    $list.GetItemById($file.ListItemId).Recycle() | Out-Null    

He developed a short little set of PowerShell Functions that can take ownership of the files, then recursively check in all files that are being checked out by the system account. tryt his

#Add SharePoint Snapin if not using SharePoint's PowerShell Console
if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
Add-PsSnapin Microsoft.SharePoint.PowerShell
#First function takes ownerhip of all unmanaged files with no version
function Take-Ownership{
$site = Get-SPWeb -Identity $spSite
$list = $site.Lists[$spList]

$list.CheckedOutFiles | ForEach-Object{
$_.LeafName+ " had it's ownership taken from: "+$_.CheckedOutBy.DisplayName+"`n"
#This Function takes a folder object and recursively checks in
#all files which are checked out by the System Account
function checkin-AllFiles{
[Parameter(Mandatory=$true, ValueFromPipeline=$true)]

$currFolder.Files | ForEach-Object {
if ($_.CheckedOutByUser.UserLogin -eq "SHAREPOINT\system"){
$_.CheckIn("File checked in by administrator")
$_.Name+" has been checked in`n"
$currFolder.SubFolders| ForEach-Object{
checkin-AllFiles -currFolder $_
#This function basically combines the previous 2 for primary use
function Checkin-AllUnmanagedFiles{
$spSite = Get-SPWeb -identity $site
$spFolder = $spSite.Folders[$library]

"Taking ownership of the following Files`n"
Take-Ownership -spSite $site -spList $library

"Checking in the following files`n"
checkin-AllFiles -currFolder $spFolder


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.