[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
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,473 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

656 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