I am attempting to write a powershell script that will iterate through all document libraries and provide me with the default values for specific columns.
I am successfully iteration through the sites, and their respective lists, but for a column named "NH Department" I would like to know if a default value has been set or not, and if so, what the default value is. I have tried the following with no success (partial, applicable code below):
foreach ($list in $subWeb.Lists)
{
$listname = $list.Title
$FieldName = $list.Fields["NH Department"]
Write-Output $("NH Department: " + $FieldName.value)
}
I guess I don't know how to query the VALUE of the field I am targeting. I am not even confident I am finding the field properly above (probably not).
The fields in question are Managed Metadata fields that are part of a site column, which in turn is part of a content type applied to the document library.
EDIT: Complete code
$webApplicationURL = "http://www.site.com/"
$webApp = Get-SPWebApplication $webApplicationURL
if($webApp -ne $null)
{
$webAppName = $webApp.name
Write-Output "Web Application : $webAppName"
foreach($siteColl in $webApp.Sites)
{
if($siteColl -ne $null)
{
$siteCollName = $siteColl.Url
Write-Output "Site Collection : $siteCollName"
foreach($subWeb in $siteColl.AllWebs)
{
if($subWeb -ne $null)
{
$subWebName = $subWeb.Title
Write-Output "Site : $subWebName"
foreach ($list in $subWeb.Lists)
{
$listname = $list.Title
if($lastlistname -ne $listname){Write-Output "List: $listname"}
$FieldName = $list.Fields["NH Department"]
Write-Output $("NH Department: " + $FieldName.DefaultValue)
}
$subWeb.Dispose()
}
else
{
Echo $subWeb "does not exist"
}
}
$siteColl.Dispose()
}
else
{
Echo $siteColl "does not exist"
}
}
} else
{ Echo $webApplicationURL "does not exist, check the WebApplication name"
}