Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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

Update: Output has been added

enter image description here

share|improve this answer
    
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 MCSA Mar 5 '13 at 20:33
    
@BennySkogberg Well, but based on my testing it works. Screenshot: i.stack.imgur.com/J1R0A.png –  Andrey Markeev Mar 5 '13 at 20:44
    
@AndreyMarkeev I must be doing something wrong further up the chain, then. That's strange :-S –  Benny Skogberg MCSA Mar 5 '13 at 20:51
    
@FalakMahmood Amazing! It must be my environment then. Thanks +1 and accepted answer! –  Benny Skogberg MCSA Mar 5 '13 at 20:54
    
I have simplified your code. Try this paste pastebin.com/g6TBpe10 –  Falak Mahmood Mar 5 '13 at 20:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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