2

I try to use powershell to deploy a build (Visual Studio) to multiple remote server. The problem is, that the powershellscript does not copy the folders like I intendet to. I use the following powershell command to copy the published website to the destinations.

Copy-Item -Path D:\Websites\$(ProjectName)\ -Recurse -Destination \\%RemoteServer%\D$\Websites\$(ProjectName)\ -Container -Exclude *.config -force

When the folder on the remoteserver does not exist, everything works fine. But if the folder exists, all files are copied into a new subfolder instead of overwriting the existing ones.

So in the first execution the destination is corrected and looks like this:

D:\Websites\TestWebsite\ {all files}

After a second copy, the destination of the copy is:

D:\Websites\TestWebsite\Publish\ {all files}

The variables ProjectName and RemoteServer are in both executions the same.

11
  • See here: stackoverflow.com/questions/6500320/… Commented Feb 11, 2019 at 6:30
  • @f6a4 - the execution of the powershell script is working fine. Only the result is not the behavior I expected, because the copied files are note moved to the directory I want. Commented Feb 11, 2019 at 6:35
  • 1
    You have to submit "$(Projectname)" and %Remoteserver% as parameter to the script (alternatively you can use [environment]::Remoteserver in powershell for the servername). To check if all is right, just write the complete paths to a text file ($path | Out-File "test.txt"). I'm sure that something is wrong with the parameters. Commented Feb 11, 2019 at 7:03
  • 2
    Well, here you go Commented Feb 11, 2019 at 7:40
  • 1
    I'd just use robocopy for this - it's purpose built for file copy operations and is very well documented. Commented Feb 11, 2019 at 8:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.