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
source link
https://social.technet.microsoft.com/Forums/en-US/df09db52-1af8-4ef0-9999-57d8496a148a/exclude-few-sub-folders-while-copying-to-remote-server?forum=winserverpowershell