Register
: :
Login
Home
Forums
Blogs
Podcast
Directories
Scripts
Downloads
Community
User Group Support
Learning Resources
We have a new sponsor! Introducting
Pragma Systems
. See the home page for details.
Unanswered
Active Topics
Forums
Search
Members
Forums
>
Using PowerShell
>
SharePoint
Returning Item Values from a List.
Last Post 28 Jul 2009 04:40 PM by
Pilkentonc
. 1 Replies.
Sort:
Oldest First
Most Recent First
Prev
Next
You are not authorized to post a reply.
Author
Messages
Russ
New Member
Posts:1
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
Pilkentonc
New Member
Posts:10
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.
PowerShellCommunity.org
--Community Announcements and Assistance
--Completely Unrelated
--User Groups
--Community Business
----Suggestion Box
Using PowerShell
--General PowerShell
--Books, Tools, and Videos
--Exchange Server
--Active Directory
--System Center Family
--Non-Microsoft Products
--SharePoint
--SQL Server
--Working with .NET
--Peer Review
--Testing, Testing...
PowerShell Development
--Cmdlet Development
--PSDrive Provider Development
--Hosting the Shell
Looking Ahead
--Using PowerShell v2.0
--Developing for PowerShell v2.0
Forums
>
Using PowerShell
>
SharePoint
Active Forums 4.1
Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008