Change the Content Type for All Documents in a Library

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!

September 11th, 2015 12:24pm

This script clearly is for SharePoint on-prem version.

Free Windows Admin Tool Kit Click here and download it now
September 11th, 2015 2:44pm

Hi Chasquad,

The PowerShell commands only work for SharePoint On-premise, not for SharePoint Online.

For SharePoint Online PowerShell, there are some limitations of function.

There is a TechNet article about PowerShell for SharePoint Online cmdlets:

https://technet.microsoft.com/en-us/library/fp161364.aspx

For your requirement, I think, there is no way except changing them manually.

Thanks,

Wendy

September 13th, 2015 10:42pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics