Enumerate through SharePoint lists | Complete Action RRS feed

  • Question

  • Here is my code: 

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


    function FindLists() { 

        $site = New-Object Microsoft.SharePoint.SPSite($url) 
        $site.OpenWeb() | foreach { $_.Lists | test([string]$_.Lists) } 



    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? 


    Tuesday, June 22, 2010 2:04 PM

All replies

  • [string]$url = "http://sp/Dashboard"
    [string]$Field = "ProjectID"
    [string]$Item = "5"
    function FindLists([string]$url) { 
      $site = Get-SPWeb $url
      $site.Lists | foreach { main([string]$_.Title) } 
    function test([string]$list) { 
      write-host -url $url -List $list -Item $Item -Field $Field -site $SPsite
    function main([string]$List, $site) {
      Remove-SPItem -url $url -List $List -Item $Item -Field $Field -Site $site
    function Get-SPSite([string]$url) {
    	New-Object Microsoft.SharePoint.SPSite($url)
    function Get-SPWeb([string]$url) {
    	$SPSite = Get-SPSite $url
    function Remove-SPItem([string]$url, [string]$List, [string]$Item, [string]$Field) {
    	$OpenWeb = Get-SPWeb $url
    	$OpenList = $OpenWeb.Lists[$List]
    	if($OpenList.Items | where { $_[$Field] -eq $Item }) {
    		$OpenItem = $OpenList.Items | where { $_[$Field] -eq $Item }
    		$OpenItem | ForEach-Object { $_.Delete() } 
    	} else {
    		Write-Host "-url $url -List $List Item $Item Not Found in this List: $List on this field $Field"
    FindLists $url

    I've updated my code but I'm having an issue with it. When ran, I get this error message:
    The following exception was thrown when trying to enumerate the collection: "Server Out Of Memory
    There is no memory on the server to run your program. Please contact your administrator with this problem.".

    Can someone give me some insight into this error message?

    Friday, June 25, 2010 3:14 AM