1

Description

I have written a PowerShell script that loops for all the documents and folders in a web application. The script write specific information about those documents and folders into a separate CSV file per site collection. The logic looks like below:

Script

#...Previous code to retrieve the document library in a site collection...
$csvData = @()
$_.Lists | ? { $_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $false } | foreach {
    [Microsoft.SharePoint.SPFolder]$rootFolder = $_.RootFolder
    #Recursive function to loop all folders and documents in the library
    $csvData += Recursive-RootFolder $rootFolder $csvData
}
#If the $csvData holds information then Export-Csv

The Recursive-RootFolder is a function that loops the library's root folder and its subfolders/documents, and when a certain criteria is matched the function APPENDS data to the $csvData like below snippet:

$csvData += New-Object PSObject -Property @{
    SiteColUrl = $sub.ParentWeb.Site.Url
    SiteColID = $sub.ParentWeb.Site.ID
    #And so on....
}

The logic above is repeated for several libraries that live in several webs/site collections.

Problem

The problem I'm facing is with the $csvData that I'm sending as a parameter. I don't know if I'm doing it right but the $csvData seems to never hold information.

Goal

I want to be able to send the $csvData as parameter so that I can export a separate CSV file for each site collection whenever it holds data.

Thanks in advance!

  • Please post the entire script (obfuscating sensitive info if needed). – jpollar Jan 10 '17 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.