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
1,226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 53

Accepted Solution

by:
Will Szymkowski earned 500 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
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…

739 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