我有一个脚本,用于将文档及其元数据从源文档库复制到目标文档库。虽然这是正常工作,文档以及大多数元数据被正确地复制到目的地,但我遇到的问题是:
我是否需要在下面的脚本中更新以正确实现此目的?脚本片段如下所示:
Add-PSSnapin Microsoft.SharePoint.Powershell -ea SilentlyContinue
$urlWebSrc = "https://testsite.info/sites/IT"
$listNameSrc = "Documents"
$urlWebTgt = "https://vine.info/dept/IT"
$listNameTgt = "Shared Documents"
$webSrc = Get-SPWeb $urlWebSrc
$webTgt = Get-SPWeb $urlWebTgt
$src = $webSrc.Lists[$listNameSrc]
$tgt = $webTgt.Lists[$listNameTgt]
$listItems = $src.Items
$listFolders = $src.Folders
$srcRootFolderUrl = ("{0}/{1}" -f $src.ParentWebUrl, $src)
$tgtRootFolderUrl = ("{0}/{1}" -f $tgt.ParentWebUrl, $tgt)
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.Query = "<Where>
<BeginsWith>
<FieldRef Name='ContentTypeId' />
<Value Type='ContentTypeId'>0x0101</Value>
</BeginsWith>
</Where>"
$rootItems = $src.GetItems($spQuery)
foreach ($rootItem in $rootItems) {
$relative = $rootItem.Url
$targetItem = $listItems | Where-Object { $_.Url -eq $relative }
$sBytes = $targetItem.File.OpenBinary()
$dFile = $tgt.RootFolder.Files.Add($targetItem.Name, $sBytes, $true)
$dFile.Update()
$dItem = $tgt.GetItems($spQuery) | Where-Object { $_.Name -eq $targetItem.Name }
$dItem["Modified"] = $rootItem["Modified"].ToLocalTime()
$dItem["Created"] = $rootItem["Created"].ToLocalTime()
$dItem["Author"] = $rootItem["Author"]
$dItem["Editor"] = $rootItem["Editor"]
$dItem["Committee"] = $rootItem["Committee"]
$dItem["Dept"] = $rootItem["Dept"]
$dItem["Organisation"] = $rootItem["Organisation"]
$dItem["Checked Out To"] = $rootItem["Cheked Out To"]
$dItem["Content Type"] = $rootItem["Content Type"]
$ditem.Update()
Write-Host "...... File Mirroring:" $dfile.Name "- Complete"
}
foreach ($folder in $listFolders) {
$srcFolderUrl = $folder.Url
$tgtFolderUrl = $srcFolderUrl
$tgtFolderUrl = $tgtFolderUrl -replace $src, $tgt
if (!($tgt.Folders | Where-Object { $_.Url -eq $tgtFolderURL })) {
$srcParentFolderUrl = $folder.Folder.ParentFolder.ServerRelativeUrl
$tgtParentFolderUrl = $srcParentFolderURL -replace $srcRootFolderUrl,
$tgtRootFolderUrl
$newFolder = $tgt.Additem($tgtparentFolderURL,
[Microsoft.SharePoint.SPFileSystemObjectType]::Folder, $folder.Name)
$newFolder.SystemUpdate()
Write-Host "Folder Creation:" $tgtFolderURL "- Complete"
}
$tgtFolder = $tgt.Folders | Where-Object { $_.Url -eq $tgtFolderURL }
if ($folder.Folder.Files.Count -gt 0) {
$spQuery.Folder = $folder.Folder
$srcItems = $src.GetItems($spQuery)
foreach ($item in $srcItems) {
$relative = $item.Url
$targetItem = $listItems | Where-Object { $_.Url -eq $relative }
$sBytes = $targetItem.File.OpenBinary()
$dFile = $tgtFolder.Folder.Files.Add($targetItem.Name, $sBytes, $true)
$dFile.Update()
$spQuery.Folder = $tgtFolder.Folder
$dItem = $tgt.GetItems($spQuery) | Where-Object { $_.Name -eq $targetItem.Name }
$dItem["Modified"] = $item["Modified"].ToLocalTime()
$dItem["Created"] = $item["Created"].ToLocalTime()
$dItem["Author"] = $item["Author"]
$dItem["Editor"] = $item["Editor"]
$dItem["Committee"] = $rootItem["Committee"]
$dItem["Dept"] = $rootItem["Dept"]
$dItem["Organisation"] = $rootItem["Organisation"]
$dItem["Checked Out To"] = $rootItem["Cheked Out To"]
$dItem["Content Type"] = $rootItem["Content Type"]
$dItem.Update()
Write-Host "...... File Mirroring:" $dfile.Name "- Complete"
}
}
}
因此,无法正常工作的位是复制By By列,而不是复制实际用户,而是复制用户所在的sharepoint组。
同时,根本没有复制Checked out to值。
任何建议都会受到欢迎。