3

I want to delete custom content type from Pages library but it did not allow me to delete and says "content type is still in use". Then i get to know that i need to delete it from following locations as well: 1. Root site Recycle bin 2. End user recycle items 3. Deleted from end user recycle bin

After deleting from these locations, i was able to delete CT from Pages library successfully. But Now,
I want to write a powershell script instead to delete only those specific items from above three locations that still having reference these content types. How i specify only those items in my script? any example can help me?

I don't want to delete all items from recycle bin

  • 1
    You can apply checks on specific items like checking their content type. If Content Type == "ABC" then delete the item from pages library. – Falak Mahmood Feb 22 '16 at 15:56
0

You can cycle through all items in recycle bin, but they do not contain property "Content type".

$web = Get-SPWeb "https://contoso.com"
foreach($item in $web.RecycleBin)
{
    # delete based on directory
    if($item.DirName -like "AwesomeFolder/*")
    {
        $item.Delete();
    }
}

$web.Dispose();
Write-Host "End" -BackgroundColor DarkGreen -ForegroundColor Green

# EXAMPLE OF ITEM IN RECYCLE BIN
#Web            : Contoso
#ID             : 61abc558-40a7-45d2-8af5-673963742a1e
#ItemState      : FirstStageRecycleBin
#ItemType       : File
#Title          : Document for testing
#DirName        : AwesomeFolder/2018/
#LeafName       : test.docx
#Author         : Domain\User1
#AuthorId       : 30
#AuthorName     : Domain\User1
#AuthorEmail    : user1@contoso.com
#DeletedBy      : Domain\User1
#DeletedById    : 30
#DeletedByName  : Domain\User1
#DeletedByEmail : user1@contoso.com
#DeletedDate    : 09.11.2018 10:02:43
#Size           : 110474
#ProgId         : 
#ImageUrl       : /_layouts/images/icdocx.png

If You can guess CT from library and path (DirName) or title (Title), then You are lucky. If not, there is one long and painful way (unsupported by Microsoft) - get data from SQL database directly. I cannot give precise SQL queries, but the idea is like this :

1) get all items from [RecycleBin] table

2) use IDs to locate items in [AllDocs] table

3) decompress data in [MetaInfo] column --> here You will find Content type :)

4) use column [DoclibRowId] value to delete items in recycle bin by column [Id]

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.