I have looked up a couple of resources on changing Content Types via Powershell without much luck. It seems no matter what I run, it's not changing the content type in a way I would expect.
I got a list of the Content Types for this library that looks like this:
$site = Get-SPWeb http://site.domain/divisions/subsite/
$list = $site.Lists["Library"]
$list.ContentTypes
ID Name
-- ----
0x0101009B1F3022B2A90E49A6CD5145086FDAEC Document
0x01010007720F65506030408FC83D80894F3A1A00DB58F20FB2BAB447A51247E4B3572289 Emptoris Template
0x010104009F19CD75D7052E4493C7E57BC5A1CF9E Unknown Document Type
0x010100F1586A0694934346BEFFFE9F6B8F77F300F242E8A6489E3D45915F1D1401E34581 Excel Document
0x01200040A3BEB3A63808458EC6ED84B5E81E75 Folder
And then I used a "where" statement to get my file:
$file = $list.items | where {$_.url -like "library name/folder name/file*"}
This returns the file I am looking for, and nothing else. So I run a foreach loop that returns information on the file, updates the content type, then returns the new information:
foreach($item in $file)
{
$item.Name
$item.ContentTypeId
$itemfile = $item.file
$itemfile.CheckOut()
$item["ContentTypeId"] = "0x010104009F19CD75D7052E4493C7E57BC5A1CF9E "
$itemfile.Update()
$itemfile.CheckIn("")
$item.Name
$item.ContentTypeId
}
This shows updates information in the PowerShell window, but it is certainly NOT what I would expect, and it does not change the Content Type on the GUI interface, regardless of what the PowerShell prompt displays. Here is an example of running this code, where I attempt to change the Content Type to Document:
foreach($item in $file)
>> {
>> $item.Name
>> $item.ContentTypeId
>> $itemfile = $item.file
>> $itemfile.CheckOut()
>> $item["ContentTypeId"] = "0x0101009B1F3022B2A90E49A6CD5145086FDAEC"
>> $itemfile.Update()
>> $itemfile.CheckIn("")
>> $item.Name
>> $item.ContentTypeId
>> }
>>
DocumentName.docx
Parent
------
0x
DocumentName.docx
0x0101
It shows updating the file. But looking on the UI side, it still shows "Emptoris Template" as the Content Type:
I can try and change this to any of the Content Types that are shown, and it "changes" in PowerShell, but never to the Content Type ID that I set it to, but instead just the "Parent" Content Type is shown. This is a standard .docx file, so the "Document" content type should definitely be able to be applied.
I'm sure it's simple, but I'm at a loss on this one.