header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

Returning Item Values from a List.
Last Post 28 Jul 2009 04:40 PM by Pilkentonc. 1 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
RussUser is Offline
New Member
New Member
Posts:1
Avatar

--
09 Jul 2009 03:56 PM  
I have a custom SharePoint list, that has 3 fields, Title, UserName, Location. Can someone please point me in the right direction to write a simple script that will return the 3 columns for each Item in the list... I can return Title happily, but not UserName or Location.

So far I've Got:
$spsite = new-object Microsoft.SharePoint.SPSite("http://SiteURL/")
$web = $spsite.OpenWeb() $list = $web.Lists["ListName"]
$list.Items | select Title

$list.Items | select Title, UserName, Location
BUT this doesn't return the extra columns.


All help gratefully received.
Russ
PilkentoncUser is Offline
New Member
New Member
Posts:10
Avatar

--
28 Jul 2009 04:40 PM  
I have had similar problems getting the SharePoint Object Model to give values back like that. Here is a .ps1 script I created to do this for me. You could enhance the foreach sequence to enumerate all fields instead of calling them directly. Hope this helps.


## .\SharePoint_List_Read.ps1 "https://home.mysharepoint.com" "/" "SharePoint FAQ's" "YES"
## .\SharePoint_List_Read.ps1 "https://home.mysharepoint.com" "/" "SharePoint FAQ's"

param(
[string] $rqurdstrPath = $(Throw "--SharePoint Core Path required."), #required parameter
[string] $rqurdstrPashSubweb = $(Throw "--SharePoint Path Subweb required."), #required parameter
[string] $rqurdstrListName = $(Throw "--SharePoint List Name required."), #required parameter
[string] $strShowResults = "NO"
)

## Global Variables ##
$intCounter=1

write-host "rqurdstrPath: $rqurdstrPath "
write-host "rqurdstrPashSubweb: $rqurdstrPashSubweb "
write-host "rqurdstrListName: $rqurdstrListName "
write-host "intCounter: $intCounter "

## Load SharePoint assembly ##
[void][System.reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

$site=new-object Microsoft.SharePoint.SPSite($rqurdstrPath)
#$site.AllWebs
$subWeb = $site.OpenWeb($rqurdstrPashSubweb)

write-host "site: $site "
write-host "subWeb: $subWeb "
##$subWeb | foreach { $_.Lists | ft $_.Url, Title}#$subWeb.Lists

$list=$subWeb.Lists[$rqurdstrListName]
#$list

$newitem=$list.items

if($strShowResults -eq "YES") {
$intItemCount=[int]$newitem.count
write-host "intItemCount: $intItemCount "
for($aa=0; $aa -lt $intItemCount; $aa++) {
if($aa -eq 5) {
$newitem[$aa] | Get-Member
}
$splistItems = $newitem[$aa]
foreach($splistItem in $splistItems) {
[string]$splistItem.Id +"-"+ $splistItem.Title
"**"+ $splistItem.DisplayName
}
}
}
else {
$newitem
}

$subWeb.Dispose()
$site.Dispose()

## End of submit ##
Craig Pilkenton
SharePoint Engineer
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer