I'm iterating all lists in a site collection trying to get all metadata, their values and eventually count them. I'm not so far yet, but I'm stuck in getting the values from a documents (file) property corresponding keys.
function GetAllFields($url)
{
$sites = Get-SPSite $url
foreach ($web in $sites.AllWebs)
{
$lists = $web.Lists
foreach ($list in $lists)
{
if ($list.Title -like "*Document*")
{
$propertyExist = $false
foreach ($field in $list.Fields)
{
if ($field.Title -eq "Property Bag")
{
$propertyExist = $true
}
}
if ($propertyExist)
{
Write-Host $web.Name -ForegroundColor Green
Write-Host " " $list.Title -ForegroundColor Cyan
foreach ($item in $list.Items)
{
Write-Host " " $item.Name
$file = $item.File
foreach ($key in $file.Properties.Keys)
{
Write-Host " " $key -ForegroundColor Yellow -NoNewline
Write-Host " " $file[$key] -ForegroundColor White
}
}
}
}
}
}
If ($sites -ne $null)
{
$sites.Dispose();
}
If ($web -ne $null)
{
$web.Dispose();
}
}
GetAllFields http://portal
Everythings run nicely until I try to get the property value corresponding to the property key at this line:
Write-Host " " $file[$key] -ForegroundColor White
A few good hours of searching hasn't made things clearer too me. How do I get document properties.Keys value?