2

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?

1 Answer 1

2

the key's value should be in $file.Properties[$key]

Update: Output has been added

enter image description here

5
  • Thanks for your reply - but I still get no values in return. Not even vti_author is filled in as you cen see from my screenshot
    – Benny Skogberg
    Mar 5, 2013 at 20:33
  • @BennySkogberg Well, but based on my testing it works. Screenshot: i.stack.imgur.com/J1R0A.png Mar 5, 2013 at 20:44
  • @AndreyMarkeev I must be doing something wrong further up the chain, then. That's strange :-S
    – Benny Skogberg
    Mar 5, 2013 at 20:51
  • I have simplified your code. Try this paste pastebin.com/g6TBpe10 Mar 5, 2013 at 20:55
  • @FalakMahmood Thanks! And I tried in a different environment this morning - it actually did work. I'll try not to doubt you again ;-)
    – Benny Skogberg
    Mar 6, 2013 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.