Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Exclude few sub folders while copying to remote server

$
0
0

Hi.

I am trying to copy the folder and files from one server to another, based on a configuration xml.

The source folder contains data as below:

Backup

Backup\folder1

Backup\folder2

Backup\folder3 .. like this

I want to exclude folder2, folder4, folder5 and copy the other folders to destination.

Also, when copying other folders, I want to copy those folders and only the files ending with .bak in them.

My current code is copying all files and folders.

// config.xml<Config><Test><SourceDBBackupPath>\\server\D$\BACKUP</SourceDBBackupPath><DestinationRestorePath>\\server1\e$\BACKUP\;\\server2\e$\BACKUP\</DestinationRestorePath><DestinationServer>server1;server2</DestinationServer></Test></Config>

function CopyBackup($Region)
{
    if($Region -ieq "Test" )
    {
       $XPath = "Config/Test"
       $Xvalues =   Select-Xml -Path $configFile -XPath $Xpath | Select-Object -ExpandProperty Node

       $DestinationServers = $Xvalues.DestinationServer -Split ";"
       $SourcePath = $Xvalues.SourceDBBackupPath
       $DestinationPaths = $Xvalues.DestinationRestorePath -Split ";"      

       foreach ($DestinationPath in $DestinationPaths){
           Copy-Item $SourcePath -Destination $DestinationPath  -Recurse -force
       }     
       Write-Host "Files copied" 
      }
    }

Thanks


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>