Ran into an issue on a SP2010 farm that had over a million documents in a document library with a hundred thousand folders. Yes, lots of data, but not a bad practice in this case as it was tied to another system that relied on the folders.
In any case, I was unable to change information Policy on document library with many thousand folders due to SharePoint’s UI which creates a tree view of folders on the page to change the Information Policy. Not the best design. So as my browser crashed waiting for 100,000 folders to load, we came up with a Powershell script to accomplish this. This script will create an Information Policy to delete all documents inside the document library that are older than 180 days. It is applied to the content type, but is scoped to the document library itself. Other libraries on the site are safe.

Add-PSSnapin Microsoft.Sharepoint.Powershell

function CreateIMP180Days($siteURL, $listName, $contentType)
{
#Get web object
$web = Get-SPWeb $siteURL
write-host “Examining site:”$web.Title”at”$web.ServerRelativeUrl -ForegroundColor green

try
{
#Do the following if a list exists with the name specified by the user – e.g., Pages
if ($web.Lists[$listName]) {

write-host $web.Title”has a list called “$listName -ForegroundColor green

#Get the list
$list = $web.Lists[$listName]

#Create list policy if one does not exist already
$policy = [Microsoft.Office.RecordsManagement.InformationPolicy.ListPolicySettings]($list)
if (!$policy.ListHasPolicy)
{
$policy.UseListPolicy = $true
$policy.Update()
}

#Get the content type
$ct = $list.ContentTypes[$contentType]

#Create a new policy
[Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::CreatePolicy($ct, $null)
$newPolicy = [Microsoft.Office.RecordsManagement.InformationPolicy.Policy]::GetPolicy($ct)

#Generate policy XML using the values required,
$newPolicyFeatureXml = “”+
“”+
“”+
“”+

“+
“180”+
” Created”+
” days”+
“”+
“”+
“”+
“”+
“”

#Add retention policy
$newPolicy.Items.Add(“Microsoft.Office.RecordsManagement.PolicyFeatures.Expiration”, $newPolicyFeatureXml)

write-host “Added retention policy to delete documents on content type”$ct.Name”for list”$list.Title”in site”$web.Title
}
else
{
#Report if the site does not have the list specified by the user
write-host $web.Title”does not have a list called “$listName -ForegroundColor red
}
}
catch
{
write-host “There has been an error:”$_ -ForegroundColor red
}
finally
{
#Dispose of the Web object
$web.Dispose()
}
}
CreateIMP180Days -siteURL “http://url” -listName “DocLibName” -contentType “Document”