从列表创建多个文档集

时间:2015-07-31 12:40:27

标签: powershell sharepoint sharepoint-2010

我需要为此SharePoint 2010列表中的每个名称创建一个文档集。文档集标题是人员的​​名字和姓氏,文档集具有委员会名称属性,也需要设置。委员会名称来自同一个SharePoint列表。

我不明白我的代码有错误:

$ErrorActionPreference = "Stop"
$url = "http://SERVER/etest"
$listName = "Advisory Committee"
$doclib = "TACM Application Docments"

$web = Get-SPWeb $url;
$list = $web.Lists[$listName];
$item = $list.Items;

$item | ForEach-Object {    
    $fullName = $_['Last Name'] + ", " + $_['First Name']
    $committeeName = $_['Committee Name']

    $cType = $list.ContentTypes["Document Set"]

    [Hashtable]$docsetProperties = @{"Committee Name"=$committeeName}

        $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($doclib.RootFolder,

$fullName,$cType.Id, $docsetProperties)

}

$web.Dispose()  

我收到以下错误: ForEach-Object:找不到“Create”的重载和参数count:“4”。 在C:\ Users \ ev \ desktop \ docset.ps1:10 char:23 + $ item | ForEach-Object<<<< {     + CategoryInfo:NotSpecified:(:) [ForEach-Object],MethodException     + FullyQualifiedErrorId:MethodCountCouldNotFindBest,Microsoft.PowerShell    .Commands.ForEachObjectCommand

1 个答案:

答案 0 :(得分:0)

DocumentSet.Create method期望第一个参数是文件夹(SPFolder类型):

parentFolder

Type: Microsoft.SharePoint.SPFolder
The folder in which to create the new DocumentSet object.

在你的情况下,你传递了一个无效的对象$doclib.RootFolder,因为$doclibstring变量,可能你想要这样的东西:

$doclibName = "TACM Application Docments"
$doclib = $web.Lists[$doclibName];
$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($doclib.RootFolder,$fullName,$cType.Id, $docsetProperties)

示例

$url = "http://contoso.intranet.com"
$listTitle = "Documents"

$web = Get-SPWeb $url;
$list = $web.Lists[$listTitle]
$docSetContentType = $list.ContentTypes["Document Set"]
[Hashtable]$docSetProperties = @{}
$docSetName = "Archive"
$docSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,$docSetName,$docSetContentType.Id, $docSetProperties)
$web.Dispose() 

如何将文档集内容类型添加到库

  • 转到Library Settings,然后点击Advanced Settings
  • 设置允许管理内容类型?到Yes并点击Ok按钮
  • 点击Add from existing site content types链接并选择 Document Set内容类型,然后点击Ok按钮