@@ -298,7 +298,7 @@ function Convert-ADTDeployment
298298 # Find the hashtable in the v4 template script that holds the adtSession splat
299299 $hashtableAst = $tempScriptAst.Find ({
300300 param ($ast )
301- $ast -is [System.Management.Automation.Language.AssignmentStatementAst ] -and $ast.Left.VariablePath.UserPath -eq ' adtSession'
301+ $ast -is [System.Management.Automation.Language.AssignmentStatementAst ] -and ( $ast .Left | Get-Member - Name VariablePath) -and $ast.Left.VariablePath.UserPath -eq ' adtSession'
302302 }, $true )
303303
304304 if ($hashtableAst )
@@ -333,8 +333,20 @@ function Convert-ADTDeployment
333333 $boundParameters = ($spBinder ::BindCommand($saiwAst , $true )).BoundParameters
334334 $closeProcesses = $null
335335 if ($boundParameters.TryGetValue (' CloseProcesses' , [ref ]$closeProcesses )) {
336+ if ($closeProcesses.Value | Get-Member - Name VariablePath)
337+ {
338+ $assignmentAst = $inputScriptAst.Find ({
339+ param ($ast )
340+ $ast -is [System.Management.Automation.Language.AssignmentStatementAst ] -and ($ast.Left | Get-Member - Name VariablePath) -and $ast.Left.VariablePath.UserPath -eq $closeProcesses.Value.VariablePath.UserPath
341+ }, $true )
342+ $appProcessesToClose = if ($assignmentAst ) { $assignmentAst.Right.Extent.Text } else { ' @()' }
343+ }
344+ else
345+ {
346+ $appProcessesToClose = $closeProcesses.Value.Extent.Text
347+ }
336348 Write-Verbose - Message " Updating variable [AppProcessesToClose]"
337- $hashtableContent = $hashtableContent -replace " (?m)(^\s*AppProcessesToClose\s*=)\s*@\(\)" , " `$ 1 $ ( $closeProcesses .Value.Extent.Text ) "
349+ $hashtableContent = $hashtableContent -replace " (?m)(^\s*AppProcessesToClose\s*=)\s*@\(\)" , " `$ 1 $appProcessesToClose "
338350 }
339351 }
340352
@@ -392,7 +404,7 @@ function Convert-ADTDeployment
392404 if (Test-Path - LiteralPath $Destination )
393405 {
394406 Write-Verbose - Message " Removing existing destination folder [$Destination ]"
395- Remove-Item - LiteralPath $Destination - Recurse - Force - ErrorAction SilentlyContinue - WhatIf
407+ Remove-Item - LiteralPath $Destination - Recurse - Force - ErrorAction SilentlyContinue
396408 }
397409
398410 # Sometimes previous actions were leaving a lock on the temp folder, so set up a retry loop
@@ -401,18 +413,18 @@ function Convert-ADTDeployment
401413 try
402414 {
403415 Write-Verbose - Message " Moving folder [$tempFolderPath ] to [$Destination ]"
416+ [System.Threading.Thread ]::Sleep(500 )
404417 Move-Item - Path $tempFolderPath - Destination $Destination - Force - PassThru:$PassThru
405418 Write-Information - MessageData " Conversion successful: $Destination "
406419 break
407420 }
408421 catch
409422 {
410- Write-Verbose - Message " Failed to move folder. Trying again in 500ms."
411- [System.Threading.Thread ]::Sleep(500 )
412423 if ($i -eq 4 )
413424 {
414425 throw
415426 }
427+ Write-Verbose - Message " Failed to move folder. Trying again in 500ms."
416428 }
417429 }
418430
0 commit comments