Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Break apart powershell arguments dynamically
steps:
- task: PublishBuildArtifacts@1
displayName: Publish Artifact: DynamicPowerShellArguments
inputs:
PathtoPublish: test.ps1
ArtifactName: DynamicPowerShellArguments
publishLocation: Container
Write-Verbose "Started process" -verbose
$DynamicParams = @{}
switch -Regex ($args) {
'^-' {
# Parameter name
if ($name) {
$DynamicParams[$name] = $value
$name = $value = $null
}
$name = $_ -replace '^-'
}
'^[^-]' {
# Value
$value = $_
}
}
if ($name) {
$DynamicParams[$name] = $value
$name = $value = $null
}
$DynamicParams.GetEnumerator() | ForEach-Object {
Write-Verbose "$($_.Key) $($_.Value)" -verbose
}
Write-Verbose "Completed process" -verbose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.