Skip to content

Commit c1b8e26

Browse files
committed
Handle AppProcessesToClose session variable
1 parent b989653 commit c1b8e26

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/PSAppDeployToolkit.Tools/Public/Convert-ADTDeployment.ps1

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ function Convert-ADTDeployment
130130
$variableReplacements = @('appVendor', 'appName', 'appVersion', 'appArch', 'appLang', 'appRevision', 'appScriptVersion', 'appScriptAuthor', 'installName', 'installTitle')
131131

132132
$customRulePath = [System.IO.Path]::Combine($MyInvocation.MyCommand.Module.ModuleBase, 'PSScriptAnalyzer\Measure-ADTCompatibility.psm1')
133+
134+
$spBinder = [System.Management.Automation.Language.StaticParameterBinder]
133135
}
134136

135137
process
@@ -322,8 +324,22 @@ function Convert-ADTDeployment
322324
}
323325
}
324326

325-
Write-Verbose -Message 'Updating variable [appScriptDate]'
326-
$hashtableContent = $hashtableContent -replace "(?m)(^\s*appScriptDate\s*=)\s*'[^']+'", "`$1 '$(Get-Date -Format "yyyy-MM-dd")'"
327+
# Update AppProcessesToClose if Show-ADTInstallationWelcome -CloseProcesses is present in the converted script
328+
$saiwAst = $tempScriptAst.Find({
329+
param ($ast)
330+
$ast -is [System.Management.Automation.Language.CommandAst] -and $ast.GetCommandName() -eq 'Show-ADTInstallationWelcome'
331+
}, $true)
332+
if ($saiwAst) {
333+
$boundParameters = ($spBinder::BindCommand($saiwAst, $true)).BoundParameters
334+
$closeProcesses = $null
335+
if ($boundParameters.TryGetValue('CloseProcesses', [ref]$closeProcesses)) {
336+
Write-Verbose -Message "Updating variable [AppProcessesToClose]"
337+
$hashtableContent = $hashtableContent -replace "(?m)(^\s*AppProcessesToClose\s*=)\s*@\(\)", "`$1 $($closeProcesses.Value.Extent.Text)"
338+
}
339+
}
340+
341+
Write-Verbose -Message 'Updating variable [AppScriptDate]'
342+
$hashtableContent = $hashtableContent -replace "(?m)(^\s*AppScriptDate\s*=)\s*'[^']+'", "`$1 '$(Get-Date -Format "yyyy-MM-dd")'"
327343

328344
# Update the content of the v4 template script
329345
$start = $hashtableAst.Right.Extent.StartOffset

0 commit comments

Comments
 (0)