Solved

Get sharepoint document library column value

Posted on 2010-11-09
4
2,943 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 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