#If Target subdir does not exist, create it
If (!(Test-Path -Path "$TargetDirectory")) {New-Item -ItemType:Directory -Path:"$TargetDirectory"}
#For each input file, copy to target directory
[array]$ArFiles = $Files.Split(",")
ForEach ($File in $ArFiles){
$ArFilePath = $File.Split("\")
$FileName = $arFilePath[$arFilePath.Length -1]
If ((Test-Path -Path "$TargetDirectory") -and (Test-Path -Path "$File")){
$TargetFile = $TargetDirectory + "\" + $FileName
If (!(Test-Path -Path $TargetFile)){
Try{
Copy-Item "$File" "$TargetDirectory"
Write-output "Copied agent file: $File to the directory: $TargetDirectory"
}
Catch{
Write-output "Failed to copy agent file: $File to the directory: $TargetDirectory"
}
}
}Else{
Write-output "Failed to copy agent file: $File to the directory: $TargetDirectory. The source or target does not exist."
}
}
#Remove old versions of these agent kits from target directory
If (Test-Path -Path "$TargetDirectory"){
If (($PlatformID.Length -gt 0) -and ($CurrentVersion -match "scx-"))
{
get-childitem "$TargetDirectory\scx-*.$PlatformID.*" | ForEach-object{
if ($_.Name -notmatch "$CurrentVersion"){