0

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 "***********"
Raf
  • 9,681
  • 1
  • 29
  • 41
Arviddk
  • 103
  • 2

1 Answers1

0

Also add this line above copy-item

Write-Host "Copy-Item $CopyFile $ToDirPlusUser -Recurse"

It will help you zone in on which file/directory is creating the error.

Raf
  • 9,681
  • 1
  • 29
  • 41
  • Hello - Thank you for your response. I tryed what you suggested, but I still get the same error as shown in the picture. /David. – Arviddk May 20 '14 at 13:01
  • You are going to have to post the error _and_ translate it. My Danish is a bit rusty.. – Raf May 20 '14 at 13:13
  • Also add this line above `copy-item` `write-host "Copy-Item $CopyFile $ToDirPlusUser -Recurse"`, it will help you zone in on what's going wrong and where. – Raf May 20 '14 at 14:45
  • I found out that it fails when trying to copy the bookmarks and places.sqlite files because the path doesn't exist on the local computer. So if I first create "c:\DavidTest_DataMappe\AppData\Local\Google\Chrome\User Data\Default" then I can successfully copy the bookmarks file. – Arviddk May 22 '14 at 09:37
  • Good stuff, I amended the answer. – Raf May 22 '14 at 10:11