Public/Get-CommandWithArgs.ps1
function Get-CommandWithArgs { param ( [Parameter(Position = 0)][string]$Command, # The base command [array]$Args = @() # An array of argument tuples: (Condition, Argument) ) # Initialize the result with the base command $result = $Command ForEach ($arg in $Args) { $condition, $value = $arg # Only add the argument if the condition evaluates to true If ($condition) { $result += " $value" } } return $result } |