How to copy the contents of one folder to another using Custom Scripts?

I have the following PowerShell script as a step in my automated deployment,

Write-Host "Starting"
Write-Host $OctopusParameters['Octopus.Project.Name']
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']) -force
Write-Host "First"
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\Arc') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\Items') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\category_icon') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\CommentItems') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\Content') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\crash-logs') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\DigitalSignature') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\uploads') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\EditedPages') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\expense') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\feeds') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\help-files') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\logos') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\Notification') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\pspdf_xml') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\Download') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\Upload') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\temp_pdf') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\themes') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\Waters') -force
New-Item -ItemType directory -Path ('E:\projects\'+$OctopusParameters['Octopus.Project.Name']+'\content\CommentItems') -force

Write-Host "Second"
$file = "E:\projects\"+$OctopusParameters['Octopus.Project.Name']+"\content"
Write-Host $file
$Acl = (Get-Item $file).GetAccessControl('Access')
Write-Host "Third"
$Ar = New-Object  system.security.accesscontrol.filesystemaccessrule("USERS","Modify","Allow")
Write-Host "4"
$Acl.AddAccessRule($Ar)
Write-Host "5"
Set-Acl $file $Acl
Write-Host "6"

On the same server that I am deploying this step, I have the same folder with the same name but with all the data that I need to move while deploying through Octopus. The other file is at the location:

E:\Projects\Base\version1\content

Please help me modify the script to copy this folder.

Thank you,
Deepshikha

Hi Deepshikha,

Thanks for reaching out. With Octopus we try to provide our users standardized ways to deploy their code following best practices. We generally do not provide support in writing custom scripts for very specific scenarios. On the other hand, we try to help users to use with our already existing features, which really cover most of the known scenarios.

If possible I would like to understand why are you trying to copy code from E:\Projects\Base\version1\content to that other custom directory. Where are you initially deploying the code during your deployment? is it to E:\Projects\Base\version1\content and then you want to make copies of this in other folders?

Best regards,
Dalmiro

Hi Dalmiro,

I am trying to copy the contents of the folder from: E:\Projects\Base\version1\content to a folder at location: E:\Projects\content. I am doing that because I have some manually entered data that needs to be present for my automated build.

I am initially deploying the code to this location: E:\Projects\content. ‘content’ folder on this location is created by Octopus and has no data. That’s the reason I want to copy data to this folder.

Thank you,
Deepshikha

Hi Deepshikha,

So you initially deploy your package contents to E:\Projects\content, but then you want to copy custom files that were not originally included in the package from E:\Projects\Base\version1\content to E:\Projects\content.

If I did get the above right, then yeah you’ll need a custom script to do this that contemplates paths/duplicate files scenarios. The cmdlet you need to look at is Copy-Item https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.management/copy-item

Best regards,
Dalmiro

Hi Dalmiro,

Yes, that’s correct.

Thank you for your reply.

Regards,
Deepshikha