header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Enumerate through SharePoint lists | Complete Action
Last Post 24 Jun 2010 03:14 PM by iOnline247. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
iOnline247User is Offline
New Member
New Member
Posts:9
Avatar

--
23 Jun 2010 07:10 AM
    Here is my code: [string]$url = "http://sp/Dashboard" [string]$Field = "ProjectID" [string]$Item = "3" [void] [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") function FindLists() { $site = New-Object Microsoft.SharePoint.SPSite($url) $site.OpenWeb() | foreach { $_.Lists | test([string]$_.Lists) } $site.Dispose() } function test([string]$list) { write-host -url $url -List $list -Item $Item -Field $Field } I know where it's failing and that's because $list is returning all of the lists all at once. The function test's output looks like: -url http://sp/Dashboard -List Action Items Benchmarking Cost Control Calendar Custom workflow process fpdatasources FTP Requests Master Page Gallery Project Manager Quick Links Tasks Workflow History W orkflows -Item 3 -Field ProjectID I need to only have it send one list to my function at a time. I think I need to build an array of lists and pass them into my function. Does anyone know how to do that? Cheers, Matt
    Craig PilkentonUser is Offline
    New Member
    New Member
    Posts:11
    Avatar

    --
    23 Jun 2010 07:51 AM
    • Accepted Answer
    As shown in your output Powershell is doing exactly as you asked it to do, whether it makes sense or not.

    If you only want one of the Lists, add a Where clause after the following section before the pipe "$_.Lists".

    For enumerating through all the Lists, create a $Lists object by calling the $site.Lists method. Then foreach through the $Lists, passing a $List object, or just the List name, to your function.
    Craig Pilkenton
    SharePoint Engineer
    iOnline247User is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    24 Jun 2010 02:54 PM
    Would you be able to help me along? I've change the code based off of your recommendations and here's the new version. I am trying to send all of the lists to the test function. I'd like to only have to update the $url and then let the script know what to do.

    [string]$url = "http://sp/Dashboard"
    [string]$Field = "ProjectID"
    [string]$Item = "3"

    [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

    function FindLists() {
    $site = New-Object Microsoft.SharePoint.SPSite($url)
    $Lists = $site.OpenWeb().Lists.Title
    echo $Lists
    #foreach-object { test $Lists }
    $site.Dispose()

    }

    function test([string]$list) {
    write-host -url $url -List $list -Item $Item -Field $Field
    }

    FindLists


    I was doing $Lists = $site.OpenWeb().Lists but that returns a whole bunch of xml that I don't know how to filter. I feel I'm close though, do you know how to tweak this to get this working?
    iOnline247User is Offline
    New Member
    New Member
    Posts:9
    Avatar

    --
    24 Jun 2010 03:14 PM
    • Accepted Answer
    I kept plugging away and I finally got it! I was simply looking at the ForEach operator wrong. Here's the code that works:
    [string]$url = "http://sp/Dashboard" [string]$Field = "ProjectID" [string]$Item = "3" [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") function FindLists() { $site = New-Object Microsoft.SharePoint.SPSite($url) $site.OpenWeb().Lists | foreach { test([string]$_.Title) } $site.Dispose() } function test([string]$list) { write-host -url $url -List $list -Item $Item -Field $Field } FindLists
    You are not authorized to post a reply.


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