Powershell Script to extract metadata of records in document library

Posted on 2012-08-28
Last Modified: 2012-08-30
Hi Experts,

I am writing a powershell script to read the metadata of all records in document library in SharePoint 2007.

I am able to read the records but could not figure out how to read the values. Pls help.

Question by:NicksonKoh
    LVL 38

    Expert Comment

    2010 version....

    $web=Get-SPWeb http://
    $list=$web.Lists["name of list"]
    $list.Items | select Title, DisplayName

    The select statement is where you select what columns you want to pull back.  If you want them all, put "*"
    LVL 6

    Accepted Solution

    This works in MOSS 2007

    Firstly you'll need to get access to the Site Collection

    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-Null
    $siteCollection = New-Object Microsoft.SharePoint.SPSite("")

    Open in new window

    Then you'll need to get the site that contains the document library

    $web = $sc.AllWebs | Where { $_.Url -eq "" }

    Open in new window

    Once you've got the site, you'll need to grab your list

    $list = $web.Lists["The Document Library"]

    Open in new window

    From here you should be able to enumerate all the possible items of metadata with

    $list.Fields | Select Title

    Open in new window

    Once you know the titles of the fields your looking for, you can access each item of metadata like so

    $output = @()
    foreach ($item in $items) {
        $object = New-Object -TypeName PSObject
        $object | Add-Member -MemberType NoteProperty -Name 'Title' -Value $item["Name"]
        $object | Add-Member -MemberType NoteProperty -Name 'File Type' -Value $item["File Type"]
        $object | Add-Member -MemberType NoteProperty -Name 'Url' -Value $item["Url"]
        $output += $object
    Write-Output $output

    Open in new window

    This should create a powershell object containing the metadata from your document library.
    LVL 17

    Author Comment

    Thx Fox. The code looks great.

    I tried and am getting the error at line 6
    "$object | Add-Member -MemberType NoteProperty -Name 'Title' -Value $item["Name"]"

    Cannot index into a null array.
    At D:\Batch Jobs\PowerShell Scripts\Useful Scripts\List Value of Items in a List.ps1:11 char:78
    +     $object | Add-Member -MemberType NoteProperty -Name 'Title' -Value $item[ <<<< "Name"]
        + CategoryInfo          : InvalidOperation: (Name:String) [], RuntimeException
        + FullyQualifiedErrorId : NullArray
    LVL 6

    Assisted Solution


    My mistake,

    try changing the the foreach loop to say

    foreach ($item in $list.Items) {

    Open in new window

    LVL 17

    Author Closing Comment

    Works Fantastic!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
    Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now