우리는 SharePoint 2010 환경에서 문서 라이브러리를 사용하고 있습니다. 확인 된 문서 라이브러리에는 약 200 개의 문서가 있으며 (위치 기반 - 영국 및 직원 유형 - FT) 이제이 200 개의 문서의 콘텐츠 유형을 새로운 콘텐츠 유형 'New 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)를 인쇄하지 않는다는 것입니다.
여기 몇 가지 잘못하고 있습니다. 알려주세요. (필요하다면 코드를 자유롭게 업데이트하십시오)
업데이트 후 $ item [ "ContentTypeId"] 값을 인쇄 해 보셨습니까? 맞습니까? 또한 신선한 재료를 사려고 했습니까? 이 $ updateItem = $ list.GetItemById ($ item.ID)처럼; $ updateItem.ContentType.Id –