Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

PowerShell - Unable to save Default Column Values

$
0
0

I have created a document library (A) in a Team Site. I have created 2 folders (B and C) inside the document library. I have added a content type to the library. The Content Type contains 2 columns rmName and rmKey (both internal names). I want to set a column level default on the column rmKey for folder B only. I tried the following code and this does not set the default:

$web = Get-SPWeb "http://abc:39325/sites/COSC"
$list = $web.Lists["A"]
$defaults = New-Object -TypeName Microsoft.Office.DocumentManagement.MetadataDefaults -ArgumentList $list
$folder = $web.GetFolder("sites/COSC/A/B")
$defaults.SetFieldDefault($folder, "rmKey", "Default Value")
$defaults.Update()

I tried replacing $folder with $list.RootFolder. This works, but it sets the default on the Library and both Folders instead of only folder B.

$web = Get-SPWeb "http://abc:39325/sites/COSC"
$list = $web.Lists["A"]
$defaults = New-Object -TypeName Microsoft.Office.DocumentManagement.MetadataDefaults -ArgumentList $list
$defaults.SetFieldDefault($list.RootFolder, "rmKey", "Default Value")
$defaults.Update()
What am I doing wrong in the first script? I feel there is something wrong in $folder. I tried using the Guid of "B" as weel as recursion to get folder but was not able to set the default value on "B". 


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>