Skip to content

Instantly share code, notes, and snippets.

@cpoDesign
Last active May 30, 2018 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpoDesign/b0c43553870a60d53dbac88be2d825b3 to your computer and use it in GitHub Desktop.
Save cpoDesign/b0c43553870a60d53dbac88be2d825b3 to your computer and use it in GitHub Desktop.
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