Solved

Get sharepoint document library column value

Posted on 2010-11-09
4
2,768 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
Comment Utility
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
Comment Utility
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
Comment Utility
U are correc
0
 
LVL 10

Author Closing Comment

by:shahzadbux
Comment Utility
Thank you!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

18 Experts available now in Live!

Get 1:1 Help Now