我们在 SharePoint 2010 环境中使用文档库。文档库中大约有 200 个文档已被识别(基于位置 - 英格兰和员工类型 - FT),现在我必须将这 200 个文档的内容类型更改为新的内容类型“新 FT”。我为此目的使用以下电源外壳代码-
$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 不打印更新的内容类型和更新的内容类型 ID ($newContentTypeName, $newContentTypeID)。
我在这里做错了什么吗,请指教!(如有必要,请随时更新代码)