更新文档库中现有记录的ContentType的PowerShell脚本

更新文档库中现有记录的ContentType的PowerShell脚本,powershell,sharepoint-2010,document-library,sharepointdocumentlibrary,Powershell,Sharepoint 2010,Document Library,Sharepointdocumentlibrary,我们正在SharePoint 2010环境中使用文档库。文档库中大约有200个文档已被识别(基于位置-英格兰和员工类型-FT),现在我必须将这200个文档的内容类型更改为新的内容类型“new FT”。我正在使用下面的powershell代码- $webUrl = "http://www.site.com/sites/Library/" $web = Get-SPWeb -Identity $webUrl $list = $web.Lists["CURRENT FTE"] $spQuery =

我们正在SharePoint 2010环境中使用文档库。文档库中大约有200个文档已被识别(基于位置-英格兰和员工类型-FT),现在我必须将这200个文档的内容类型更改为新的内容类型“new FT”。我正在使用下面的powershell代码-

$webUrl  = "http://www.site.com/sites/Library/"
$web = Get-SPWeb -Identity $webUrl
$list = $web.Lists["CURRENT FTE"]
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewAttributes = "Scope='Recursive'";
$spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition

    foreach($item in $listItems)
    {
        $lookup  = [Microsoft.SharePoint.SPFieldLookupValue]$item["ROLE"];   
        $role = $lookup.LookupValue;

        $EMPTYPE  = $item["EMP TYPE"]

        $lookup4  = [Microsoft.SharePoint.SPFieldLookupValue]$item["Location"];   
        $LOCATION = $lookup4.LookupValue;

        $ContentTypeName = $item.ContentType.Name
        $ContentTypeID = $item.ContentType.Id

         if ($LOCATION -eq "England") 
         {
            if($EMPTYPE -eq "FT")
            {   
                #CheckList - 1
                Write-Output  "ID - $($item.id) " 
                Write-Output  "Name - $($item.name)"
                Write-Output  "Role - $($role) "  
                Write-Output  "emptype - $($EMPTYPE) "
                Write-Output  "location - $($LOCATION) "
                Write-Output  "Content Type Name - $($ContentTypeName) "
                Write-Output  "Content Type ID - $($ContentTypeID) "
                Write-Output "  "

                $newct = $list.ContentTypes["New FT"]
                $newctid = $newct.ID

                    If (($newct -ne $null) -and ($newctid -ne $null))
                        {
                            $item["ContentTypeId"] = $newctid
                            $item.Update()

                            $newContentTypeName = $item.ContentType.Name
                            $newContentTypeID = $item.ContentType.Id

                            #CheckList - 2
                            Write-Output  "ID - $($item.id) " 
                            Write-Output  "Name - $($item.name)"
                            Write-Output  "Role - $($role) "  
                            Write-Output  "emptype - $($EMPTYPE) "
                            Write-Output  "location - $($LOCATION) "
                            Write-Output  "Content Type Name - $($newContentTypeName) "
                            Write-Output  "Content Type ID - $($newContentTypeID) "
                            Write-Output "  "
                            }



            }
        }

    } 
现在,代码标识每个文档/记录,然后按照清单-1中列出的方式打印详细信息,然后我进行更新并尝试打印清单-2中的新更新值,但问题是清单-2没有打印更新的内容类型和更新的内容类型ID($newContentTypeName,$newContentTypeID)


我是不是做错了什么,请告诉我!(如有必要,请随时更新代码)

在上面“Yevgeniy.Chernobrivets”评论的帮助下,我能够使所有字段都出现在清单-2中。根据我的评论,我必须做以下工作-

 $updateItem = $list.GetItemById($item.ID); 
$contentTypeID = $updateItem.ContentType.Id
$contentTypeName = $updateItem.ContentType.Name

更新后是否尝试打印$item[“ContentTypeId”]值?对吗?你也试过买新的吗?类似于$updateItem=$list.GetItemById($item.ID)$updateItem.ContentType.Id