我们在SharePoint 2010环境中使用文档库。文档库中有大约200个文档已经被识别(基于位置 - 英格兰和员工类型 - FT),现在我必须将这200个文档的内容类型更改为新的内容类型' New FT& #39 ;.我出于此目的使用以下电源shell代码 -
$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 " "
}
}
}
}
现在代码识别每个文档/记录,然后打印CheckList - 1上列出的详细信息,然后我进行更新并尝试在CheckList - 2中打印新的更新值 - 但问题是CheckList -2没有& #39; t打印更新的内容类型和更新的内容类型ID($ newContentTypeName,$ newContentTypeID)。
我在这里做错了,请指教! (如有必要,随时更新代码)
答案 0 :(得分:0)
在Yevgeniy.Chernobrivets'的帮助下。上面的评论,我能够使所有字段出现在CheckList - 2.根据评论,我必须在下面做 -
$updateItem = $list.GetItemById($item.ID);
$contentTypeID = $updateItem.ContentType.Id
$contentTypeName = $updateItem.ContentType.Name