0
我们在SharePoint 2010环境中使用了文档库。在文档库中有大约200个文档已经被识别(基于位置 - 英格兰和员工类型 - FT),现在我必须将这200个文档的内容类型更改为新的内容类型“新FT”。我使用下面的电源外壳代码为宗旨 -PowerShell脚本更新文档库中现有记录的ContentType
$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,然后我做一个更新,并尝试打印新的更新值在CheckList - 2 - 但问题是CheckList -2不打印更新的内容类型和更新的内容类型ID($ newContentTypeName,$ newContentTypeID)。
我在这里做错了什么,请指教! (如有必要,随时更新代码)
你试过更新后打印$项目[ “ContentTypeId”]的价值?这是对的吗?你有没有尝试过新鲜的食物?像这样$ updateItem = $ list.GetItemById($ item.ID); $ updateItem.ContentType.Id –