I'm trying to create a script that will copy over specific folders and files in C:\Users\ from three terminal servers, onto a file server. The problem is, that I create the folders on the file server based on the name of the folder i'm copying. And the script fails when it trys to create a folder on the file server, based on a file instead of a folder.
(Sorry that the text on the image is in Danish! - Hope it still might help.) I hope the script makes more sense, thanks! :)
Image: http://imgur.com/kxbzXXK
$ServerList = "\\ServerA", "\\ServerB" #Angiv hvilke servere der skal kopires fra, f.eks "\\serverA", "\\serverB".
$FromDir = "\C$\Users\" #Angiv hvilken sti der skal kopires fra, f.eks "\c$\TEST"
$ToDir = "C:\DavidTest_DataMappe\"
foreach ($Server in $ServerList)
{
$RemotePath = $Server + $FromDir
$RemoteDirs = Get-ChildItem $RemotePath |? {$_.mode -match "d"}
foreach($Username in $RemoteDirs | where-object {$_.Name.Length -le 4})
{
$FileList = "\Desktop",
#"\Documents",
#"\Music",
#"\Pictures",
#"\Videos",
#"\Favorites",
#"\Links"#,
"\AppData\Local\Google\Chrome\User Data\Default\Bookmarks",
"\AppData\Roaming\Mozilla\Firefox\Profiles\*.default\places.sqlite"
foreach($File in $FileList)
{
ECHO "Copying folder"
$ToDirPlusUser = $ToDir + $Username + $File
$CopyFile = $RemotePath + $Username + $File
Copy-Item $CopyFile $ToDirPlusUser -Recurse
}
}
}
ECHO "***********"
ECHO "***********"
ECHO "Script Done"
ECHO "***********"
ECHO "***********"