- ### Load SharePoint SnapIn
- if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
- {
- Add-PSSnapin Microsoft.SharePoint.PowerShell
- }
- ### Load SharePoint Object Model
- [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
- ### Get web and list
- $web = Get-SPWeb http://myweb
- $list = $web.Lists["List with Document Sets"]
- ### Get Document Set Content Type from list
- $cType = $list.ContentTypes["Document Set Content Type Name"]
- ### Create Document Set Properties Hashtable
- [Hashtable]$docsetProperties = @{"DocumentSetDescription"="A Document Set"}
- $docsetProperties = @{"CustomColumn1"="Value 1"}
- $docsetProperties = @{"CustomColum2"="Value2"}
- ### Add all your Columns for your Document Set
- ### Create new Document Set
- $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($list.RootFolder,"Document Set Title",$cType.Id,$docsetProperties)
- $web.Dispose()
Als weite Methoden unter [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet] steht noch folgendes zur Verfügung:
Document Set Methoden |
Mehr Details zu den Methoden findet man auch in der MSDN hier . Mit diesem Handwerkszeug sollte nichts mehr zwischen der PowerShell und Dokumentenmappen stehen!
Good Luck,
Andreas
nice post!
AntwortenLöschenThanks, your post is really helpful but I got an error message while I'm creating a document sets in line 23 of your code.
AntwortenLöschenThe command is shown below.
$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.Docu
mentSet]::Create($list.RootFolder,$docsetName,$cType.Id,$docsetProperties)
The error code is shown below.
Exception calling "Create" with "4" argument(s): "0x80070005"
At line:1 char:89
+ $newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentS
et]::Create <<<< ($list.RootFolder,$docsetName,$cTypeSharedPractice.Id,$docsetP
roperties)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
Do you have any suggestion? Thank you in advance.
Ponnuki, got that problem also and solved it. Basically, one of your arguments is probably NULL. In my case, it was because I got mixed up between DocLib content type "Document Set" and SPWeb content type "Document set". In the following example, I try to iterate over a list of OrgIds to create a docset for each one. Other difficulty: you need the .ID property of ctype, not the whole object.
AntwortenLöschen$NewSiteUrl = $WebAppUrl + "sites/" + $OrgId3.ORG_ID_3
New-SPSite -Url $NewSiteUrl -OwnerAlias $SiteOwner -SecondaryOwnerAlias $InstallAccount -Name $OrgId3.ORG_ID_3 -Template $BlankSiteTemplate
$NewSite = Get-SPWeb $NewSiteUrl
# Activate Document Set Feature
Enable-SPFeature -Identity DocumentSet -Url $NewSiteUrl
$ListTempl = GetListTemplate $NewSite
#Write-Host $ListTempl.Name
$NewSite.Lists.Add($DocumentLibraryName, $DocumentLibraryDescription,$ListTempl)
# Enable Content Types on DocLib
$DocLib = $NewSite.Lists[$DocumentLibraryName]
$DocLib.ContentTypesEnabled = $true
# Add SPWeb "Document Set" ContentType to DocLib
$DocLib.ContentTypes.Add($NewSite.ContentTypes[$DocumentSet])
$DocLib.Update()
# Find out List "Document Set" ContentType
$cType = $DocLib.ContentTypes[$DocumentSet]
# Get Opp_IDs for this ORG_ID_3
$OppIdsOrgL3s = $OppData | select OPP_ID, ORG_ID_3 | WHERE {$_.ORG_ID_3 -eq $OrgId3.ORG_ID_3} | SELECT OPP_ID | Sort-Object -Property OPP_ID -Unique
foreach ($OppIdsOrgL3 in $OppIdsOrgL3s)
{
CreateDocumentSets $DocLib $OppIdsOrgL3.OPP_ID $cType.Id
}
$NewSite.Dispose()
}
... and the function
function CreateDocumentSets($docLib, $oppId, $cType)
{
### Create new Document Set
[Hashtable]$docsetProperties = @{}
$newDocumentSet = [Microsoft.Office.DocumentManagement.DocumentSets.DocumentSet]::Create($docLib.RootFolder, $oppId, $cType, $docsetProperties)
}
Hi
AntwortenLöschenI have a document set with managed metadata property. How will you set the value for Managed Metadata field using powershell?