?
Solved

Sharepoint 2013 to copy files from each network folder to each document library  based on the names using powershell

Posted on 2013-10-28
1
Medium Priority
?
1,529 Views
Last Modified: 2014-03-27
i have 10 folders in my \\fileserver\reports named site1 through site10
I also have 10 document Libraries in \\fileserver\reports named Site1 through Site10

Is it possible to copy files from each network folder to each document library in a site based on the folder and library names ? For example, from Site1 folder copy files to Site1 library and so on...

Its a sharepoint 2013 site and i found below script but not working. can someone help me?

$Localpath = "\\fileserver\reports"
$FolderList = gci $Localpath | ?{$_.psiscontainer -eq $True} | sort name

$SiteUrl = "http://intranet.mydomain.com/client"
$web = Get-SPWeb $SiteUrl

$DestDocLibList = $web.GetListsOfType(1)

foreach ($docLib in $DestDocLibList) {
        Write-Host $docLib.Title
            }
           
foreach ($Folder in $FolderList){
    foreach ($docLib in $DestDocLibList){
     
        if ($Folder.name.ToString() -eq $docLib.Title.ToString()){
            #If we are here, it means we are ready to copy the entire contents
            #Using this syntax: Copy-Item c:\scripts\* c:\test
                $SourceFolderPath = $Localpath + "\" + $Folder.name.ToString()
                  $test2 = $SiteUrl + "/" + $docLib.Title.ToString()
                  Copy-Item $SourceFolderPath -Destination -$test2 -Recurse
            }
      }#end
}#end
0
Comment
Question by:stratoman
1 Comment
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 1500 total points
ID: 39607635
I know you are trying to do this with Powershell but might be easier to do file transfers with robocopy...

Use this example below...
robocopy source destination /E /ZB /DCOPY:T /COPYALL /R:1 /W:1 /V /TEE /LOG:Robocopy.log

Here's what the switches mean:

•source :: Source Directory (drive:\path or \\server\share\path).
•destination :: Destination Dir (drive:\path or \\server\share\path).
•/E :: copy subdirectories, including Empty ones.
•/ZB :: use restartable mode; if access denied use Backup mode.
•/DCOPY:T :: COPY Directory Timestamps.
•/COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU). Copies the Data, Attributes, Timestamps, Ownser, Permissions and Auditing info
•/R:n :: number of Retries on failed copies: default is 1 million but I set this to only retry once.
•/W:n :: Wait time between retries: default is 30 seconds but I set this to 1 second.
•/V :: produce Verbose output, showing skipped files.
•/TEE :: output to console window, as well as the log file.
•/LOG:file :: output status to LOG file (overwrite existing log).

Reference - http://community.spiceworks.com/topic/278298-move-shared-folders-and-retain-file-and-share-permissions-with-robocopy

Will.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Loops Section Overview

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question