Solved

Get sharepoint document library column value

Posted on 2010-11-09
4
2,792 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 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

22 Experts available now in Live!

Get 1:1 Help Now