简体   繁体   中英

Set the Defaultvalue for a site column in SharePoint using Powershell

I am trying to set the default value for a site column. I found following code to set the default value of a column in library, but I could not find a way to set the site column using MetadataDefaults

    add-pssnapin microsoft.sharepoint.powershell -ea silentlycontinue
[Reflection.Assembly]::LoadwithPartialName("Microsoft.Office.DocumentManagement")

$web = get-spweb http://mysitecoll/sites/Nate
$lib = $web.Lists["Shared Documents"]

 $metadataDefaults = New-Object -TypeName Microsoft.Office.DocumentManagement.MetadataDefaults -ArgumentList $web

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()

Help reference for Metadata Default members https://msdn.microsoft.com/EN-US/library/office/microsoft.office.documentmanagement.metadatadefaults_members.aspx

above code taken from http://blogs.technet.com/b/okoestner/archive/2011/12/01/fetch-default-values-of-folders-with-powershell.aspx

$web = $Global:site.RootWeb
    $field = $web.Fields["FieldName"]
    $field.DefaultValue = GUID for the value
    $field.Update($true)

The above code worked for updating the Site columns default value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM