Solved

Get sharepoint document library column value

Posted on 2010-11-09
4
2,825 Views
Last Modified: 2012-05-10
Hi

I'm running the powershell code below to get the value of two columns for each item in a document library but the dept2 field is always blank.

I've tried with fields set as text field, choice and managed metadata - dont know if this makes a difference but end game is to check against a managed metadata field.

item.title and item.name appear as expected, just not the fields i've created - i have check and the internal field names.

 


$SPSite = New-Object Microsoft.SharePoint.SPSite("http://PATH TO SITE/")
$SPWeb = $SPSite.OpenWeb()
$SPList = $SPWeb.Lists["Shared Documents"]
foreach ($listItem in $splist.Items)
{
    Write-Host $listItem.title $listItem.dept2
}
$spsite.Dispose()

Open in new window

0
Comment
Question by:shahzadbux
  • 2
  • 2
4 Comments
 
LVL 16

Expert Comment

by:quihong
ID: 34095539
Correct code below.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
$SPSite = New-Object Microsoft.SharePoint.SPSite("http://server/sites/sitename")
$SPWeb = $SPSite.OpenWeb()
$SPList = $SPWeb.Lists["Demo metadata"]
foreach ($listItem in $SPList.Items)
{
    Write-Host $listItem.Title, $listItem["ColumnName"]
}
$SPWeb.Dispose()
$SPSite.Dispose()

Open in new window

0
 
LVL 10

Author Comment

by:shahzadbux
ID: 34100050
Fantastic, that works...

Just to clarify then - for system columns $listItem.Title works but where you create a column yourself you need to use this format $listItem["ColumnName"]

Is that correct or is the difference related to site columns??
0
 
LVL 16

Accepted Solution

by:
quihong earned 500 total points
ID: 34102382
U are correc
0
 
LVL 10

Author Closing Comment

by:shahzadbux
ID: 34103163
Thank you!
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
exchange ,script 10 46
powershell script SMTP report 6 40
Get-EventLog unable to read from Text File 2 24
Delete all Messages 6 months and older - Exchange 2010 8 28
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
A brief introduction to what I consider to be the best editor for PowerShell.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 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