Skip to content

Instantly share code, notes, and snippets.

@noahpeltier
Created April 30, 2019 04:42
Show Gist options
  • Save noahpeltier/bfab8b1c515933ca78497d1607996257 to your computer and use it in GitHub Desktop.
Save noahpeltier/bfab8b1c515933ca78497d1607996257 to your computer and use it in GitHub Desktop.
Functino for building command strings dynamicaly to save to an array
$command = New-Object -TypeName System.Text.StringBuilder
$Array = New-Object -TypeName System.Collections.ArrayList
function set-arg {
[CmdletBinding()]
param (
[Parameter(ValueFromRemainingArguments)]
[String[]]$param,
[switch]$invoke = $false
)
$arg = $param -join " "
$command.Append(" $arg ")
}
Function get-arg() {
Param(
[switch]$clear,
[switch]$invoke
)
$command.toString()
If ($clear) {
$command.Clear()
}
If ($invoke) {
iex $command.toString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment