Sharepoint Export Script – Need help looping

Need assistance on writing this powershell script to where it will properly loop over itself, to where we can export multiple sharepoint databases with only using one script. For some background, the script has to be run in Powershell V2 because of how old the Sharepoint Database is. But, we are attempting to pull all of the data out of Sharepoint using Powershell and retaining the file structure. The script works flawlessly for pulling the information and keeping the database file structure intact but the problem we’re running into is: the script can only do one database at once.

Here is the script:

######################## Start Variables ######################## $destination = "\server_nameSharepoint_Export" $webUrl = "http://sharepointsite/" $listUrl = Get-Content 'C:user_namehosts.txt' ############################################################## Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue $web = Get-SPWeb -Identity $webUrl $list = $web.GetList($listUrl) function ProcessFolder { param($folderUrl) $folder = $web.GetFolder($folderUrl) foreach ($file in $folder.Files) { #Ensure destination directory $destinationfolder = $destination + "/" + $folder.Url if (!(Test-Path -path $destinationfolder)) { $dest = New-Item $destinationfolder -type directory } #Download file $binary = $file.OpenBinary() $stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create $writer = New-Object System.IO.BinaryWriter($stream) $writer.write($binary) $writer.Close() } } #Download root files ProcessFolder($list.RootFolder.Url) #Download files in folders foreach ($folder in $list.Folders) { ProcessFolder($folder.Url) } 

We need to be able to add r/http://sharepointsite/UserName/ to the hosts.txt file and have the script loop over each username once the previous database is successfully downloaded. Whenever editing this script to attempt to allow for multiple WinHosts in the Hosts file we get the following error:

GetList : Exception calling "GetList" with "1" argument(s): "<nativehr>0x80070002</nativehr><nativestack></nativestack> " At C:UsersusernameDesktopExportsharepoint.ps1:15 char:21 + $list = $web.GetList <<<< ($listUrl) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException 

Thoughts??

Thanks in advance.

submitted by /u/Thor0812
[link] [comments]

Leave a Reply