Fetch default values of folders with PowerShell
If you want to fetch folder default values with PowerShell you need to call the Method Microsoft.Office.DocumentManagement.MetadataDefaults.GetFieldDefault.
The following PowerShell script will show you how to use this method:
add-pssnapin microsoft.sharepoint.powershell -ea silentlycontinue
[Reflection.Assembly]::LoadwithPartialName("Microsoft.Office.DocumentManagement")
$web = get-spweb https://server/sites/thesite
$lib = $web.Lists["Shared Documents"]
$metadataDefaults = New-Object -TypeName Microsoft.Office.DocumentManagement.MetadataDefaults -ArgumentList $lib
foreach ($oneFolder in $lib.Folders) {
Write-Host ("Folder: {0}" -f $oneFolder.Url)
$folderObject = $web.GetFolder($oneFolder.Url)
$folderDefaultValue = $metadataDefaults.GetFieldDefault($folderObject, "ColumnName")
Write-Host (" Default Value: {0}" -f $folderDefaultValue)
}
$web.dispose()
Comments
- Anonymous
January 24, 2012
Great posting. That really helped me to get my issues solved. Strange API at this point. Thanks for your work here!