Hi
We are using Content Types for retention policies in SharePoint Online/Office 365. We have request from a Department to change the retention on all documents in a library. Using the UI is very tedious and time consuming. I contacted Microsoft and they indicated that there is no other way to do this, not even with PowerShell. I thought that someone might have come up with a solution, so I searched the World Wide Web and came across a posting that said to do this:
Run this PowerShell first:
function Reset-SPFileContentType ($WebUrl, $ListName, $OldCTName, $NewCTName){ #Get web, list and content type objects $web = Get-SPWeb $WebUrl $list = $web.Lists[$ListName] $oldCT = $list.ContentTypes[$OldCTName] $newCT = $list.ContentTypes[$NewCTName] $newCTID = $newCT.ID #Check if the values specified for the content types actually exist on the list if (($oldCT -ne $null) -and ($newCT -ne $null)) { #Go through each item in the list $list.Items | ForEach-Object { #Check if the item content type currently equals the old content type specified if ($_.ContentType.Name -eq $oldCT.Name) { #Check the check out status of the file if ($_.File.CheckOutType -eq "None") { #Change the content type association for the item $_.File.CheckOut() write-host "Resetting content type for file" $_.Name "from" $oldCT.Name "to" $newCT.Name $_["ContentTypeId"] = $newCTID $_.Update() $_.File.CheckIn("Content type changed to " + $newCT.Name, 1) } else { write-host "File" $_.Name "is checked out to" $_.File.CheckedOutByUser.ToString() "and cannot be modified" } } else { write-host "File" $_.Name "is associated with the content type" $_.ContentType.Name "and shall not be modified" } } } else { write-host "One of the content types specified has not been attached to the list"$list.Title } $web.Dispose()}
Then run this PowerShell:
Reset-SPFileContentType WebUrl <Site URL> ListName <Document library display name> OldCTName <Content type to be replaced> NewCTName <Content type to replace it with>
Well ... it doesn't seem to work. PowerShell does not return any errors.
Could someone please verify that this PowerShell is properly formatted for use with SharePoint Online? Any other ideas?
Thanks!