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,136 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 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

861 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