$VerbosePreference='continue' $WarningPreference = 'continue' $DebugPreference = 'continue' ###################################################################################### # # Projects you want to export # ###################################################################################### $list_of_projects_to_export = @("2019 TARS","2019 TARS","2022 BOU NCE TAR","2021 DHT NCE TAR") ###################################################################################### # # Command to type # ###################################################################################### $DBInstance = 'bp-srvsql05' $jra_task = 'DEPLOY-30644' $root_Destination_patch_folder = "C:\_attachements" $Destination_patch_folder = "$root_Destination_patch_folder\$jra_task" if(-not(Test-Path $Destination_patch_folder)){mkdir $Destination_patch_folder} foreach($project in $list_of_projects_to_export){ Write-Debug $project $project = $project -replace '/', ' ' #only the path $QuerySelectProjects= "SELECT a.filepath from [p_rc_bp_whiting].[dbo].[tblScope] as s INNER JOIN [p_rc_bp_whiting].dbo.tblProject as p on p.pk_projectid = s.fk_projectid INNER JOIN [p_rc_bp_whiting].dbo.tblAttachment as a on s.pk_scopeid = a.fk_scopeid INNER JOIN [p_rc_bp_whiting].dbo.tblDocumentLabel as d on a.fk_documentlabelid = d.pk_documentlabelid WHERE p.projectCode = '$project' ORDER BY projectcode, scopenr" write-output $QuerySelectProjects $targeted_Projects= Invoke-Sqlcmd -ServerInstance $DBInstance -Query $QuerySelectProjects if(-not(Test-Path $Destination_patch_folder\$project\Attachements)){mkdir $Destination_patch_folder\$project\Attachements} foreach($path in $targeted_Projects){ $exact_path = $path.ItemArray write-debug "copy $exact_path " copy-item $exact_path "$Destination_patch_folder\$project\Attachements" #Write-debug "copy in progress" } Write-Output "copy done for $project" }