Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get sharepoint document library column value

Posted on 2010-11-09
4
Medium Priority
?
3,046 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 2000 total points
ID: 34102382
U are correc
0
 
LVL 10

Author Closing Comment

by:shahzadbux
ID: 34103163
Thank you!
0

Featured Post

Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

Question has a verified solution.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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