?
Solved

Powershell Script to extract metadata of records in document library

Posted on 2012-08-28
5
Medium Priority
?
2,275 Views
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.

rgds,
Nickson
0
Comment
Question by:NicksonKoh
  • 2
  • 2
5 Comments
 
LVL 38

Expert Comment

by:Justin Smith
ID: 38340768
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 "*"
0
 
LVL 6

Accepted Solution

by:
slidingfox earned 2000 total points
ID: 38340907
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("http://url.domain.co.uk/sites/demo")

Open in new window


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

$web = $sc.AllWebs | Where { $_.Url -eq "http://url.domain.co.uk/sites/demo" }

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.
0
 
LVL 17

Author Comment

by:NicksonKoh
ID: 38348629
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
0
 
LVL 6

Assisted Solution

by:slidingfox
slidingfox earned 2000 total points
ID: 38349445
Sorry,

My mistake,

try changing the the foreach loop to say

foreach ($item in $list.Items) {

Open in new window

0
 
LVL 17

Author Closing Comment

by:NicksonKoh
ID: 38350059
Works Fantastic!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦
Screencast - Getting to Know the Pipeline

862 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