?
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,367 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 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

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

A brief introduction to what I consider to be the best editor for PowerShell.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

777 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