locked
set column default value (Source: This Folder) via powershell RRS feed

  • Question

  • When setting the default column value on a list or library there appears to be 2 options

    1. Use the default value property on the Column itself
    2. Use the "Column default value settings" within the List/Library Settings menu

    It seems that when option 1. is used, the Source of Default Value is "Document Library"
    When set via Option 2, the Source of Default Value is "This Folder"

    I can set Option 1 via powershell via List.Field.DefaultValue

    How do I set Option 2 via powershell??

    Thanks in advance,
    Jake.


    • Edited by jacobUT Wednesday, November 8, 2017 8:14 PM
    Wednesday, November 8, 2017 8:14 PM

Answers

  • ok...I got my answer here -> https://sharepointdragons.com/2013/06/07/setting-default-content-type-column-values-for-a-library-via-powershell
    • Proposed as answer by Lakshmanan SethuMVP Wednesday, November 8, 2017 10:27 PM
    • Marked as answer by jacobUT Monday, November 13, 2017 9:18 PM
    Wednesday, November 8, 2017 8:44 PM

All replies

  • Here you go.

    Looks like a known issue.

    https://social.msdn.microsoft.com/Forums/en-US/222ed501-5898-401a-b2e3-b9020af6ea3f/powershell-default-column-value-of-a-document-list?forum=sharepointdevelopmentprevious


    Please remember to click Mark as Answer on the answer if it helps you


    Wednesday, November 8, 2017 8:29 PM
  • ok...I got my answer here -> https://sharepointdragons.com/2013/06/07/setting-default-content-type-column-values-for-a-library-via-powershell
    • Proposed as answer by Lakshmanan SethuMVP Wednesday, November 8, 2017 10:27 PM
    • Marked as answer by jacobUT Monday, November 13, 2017 9:18 PM
    Wednesday, November 8, 2017 8:44 PM
  • Hi jack,

    I am glad that you have find the solution.

    You could mark your reply as an answer. It will help others who meet the similar question in this forum.

    Best regards,

    Allen Bai


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, November 9, 2017 2:53 AM
  • Here is a great PS script for you... complete solution.  Hope it helps

    # Add SharePoint Powershell 
    $ver = $host | select version
    if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} 
    if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
        Add-PSSnapin "Microsoft.SharePoint.PowerShell"
    }
    
    
    function Update-DocumentStatusValue {
    
        <#
        .SYNOPSIS
           Set column default value for document status field
    
        .DESCRIPTION
            This code fragment sets column default value for document status field
    
        .PARAMETER $web
            Require web object
    
        .PARAMETER $ListName
            Require list name
    
        .PARAMETER $DocumentStatusFieldValue
            Require document status field value (e.g: 1033;Work in Progress|0866f501-0728-41c4-a4b9-107e4ba0af75)
            This value is readed from term store
    
        .NOTE
            DocumentStatus:Reference            : 1033;#Reference|1d260605-81e1-476f-a6b4-dfa9c252a453
            DocumentStatus:Work in Progress     : 1033;#Work in Progress|0866f501-0728-41c4-a4b9-107e4ba0af75
            DocumentStatus:Final                : 1033;#Final|7a320952-b4f1-46d2-9af5-f6eafb109d26
    
    
        .EXAMPLE 
            Set-ERMRecordSecurityDefaultColumnValueRootFolder -web $web -ListName $ListName -RecordSecurityFieldValue $RecordSecurityFieldValue -Verbose
            Set column default value for Record Security field in root folder
        #>    
        [CmdletBinding()]
        PARAM (
            
            [Parameter(Mandatory=$true, HelpMessage="Please enter site url (e.g: https://blawblaw.blaw")]
    	    [string] $SiteUrl,
    
            [Parameter(Mandatory=$true, HelpMessage="Please enter list name")]
            [string] $ListName,
    
    
            [Parameter(Mandatory=$true, HelpMessage="Please enter document status field value - e.g: 1033;Work in Progress|0866f501-0728-41c4-a4b9-107e4ba0af75")]
            [string] $DocumentStatusFieldValue
        )
        BEGIN {
    
            # Add SharePoint Powershell 
            $ver = $host | select version
            if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"} 
            if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
                Add-PSSnapin "Microsoft.SharePoint.PowerShell"
            }
    
            try {
    	        $web = Get-SPWeb -Identity $SiteUrl -ErrorAction Stop
            } catch {
    	        $err = $error[0]
    	        Write-Warning  "Can not access $SiteUrl. $err"
    	        break
            }
        }
        PROCESS {
    
            $list = $web.Lists.TryGetList($ListName)
    
            if ($list -eq $null) {
                Write-Warning "List $ListName does not exited"
            } else {
    
                $currentFolder = $list.RootFolder
    
                # Provides a way to set and get default values for fields based on where the document is added.
                $columnDefaults = New-Object -TypeName Microsoft.Office.DocumentManagement.MetadataDefaults($list)
                $ColumnDefaults.SetFieldDefault($currentFolder, "DocumentStatus", $DocumentStatusFieldValue) | Out-Null
                $ColumnDefaults.Update()
    
                Write-Verbose "Set default column value for Record Security field to $DocumentStatusFieldValue"
            }
        }
        END {
    
            $web.Dispose()
        }
    }
    
    
    ######################################################## Main caller ############################################
    Remove-Variable * -ErrorAction SilentlyContinue
    $error.Clear()
    Clear-Host
    
    $SiteUrl = "https://COMPLETE SITE URL"
    $ListName = "NAme of your List"
    
    Update-DocumentStatusValue -SiteUrl $SiteUrl -ListName $ListName -DocumentStatusFieldValue "1033;#Work in Progress|0866f501-0728-41c4-a4b9-107e4ba0af75" -Verbose


    We the willing, led by the unknowing, are doing the impossible for the ungrateful. We have done so much, with so little, for so long, we are now qualified to do anything, with nothing." ~ Mother Teresa ~

    Friday, June 29, 2018 4:26 PM