Skip to content

Instantly share code, notes, and snippets.

@Packet-Lost
Last active January 18, 2020 18:29

Revisions

  1. Packet-Lost revised this gist Jan 18, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Show-ThisPSOddity.ps1
    Original file line number Diff line number Diff line change
    @@ -12,8 +12,8 @@ function Show-ThisPsOddity {

    }

    "Before the loop `$UserInput is a $(if($UserInput -is [array]){$UserInput.GetType().BaseType}else{$UserInput.GetType()})"
    "Before the loop `$UserInput is $UserInput of type $(if($UserInput -is [array]){$UserInput.GetType().BaseType}else{$UserInput.GetType()})"

    foreach($item in $UserInput) { "In the loop `$item is a $(if($item -is [array]){$item.GetType().BaseType}else{$item.GetType()})" }
    foreach($item in $UserInput) { "In the loop `$item is $item of type $(if($item -is [array]){$item.GetType().BaseType}else{$item.GetType()})" }

    }
  2. Packet-Lost created this gist Jan 18, 2020.
    19 changes: 19 additions & 0 deletions Show-ThisPSOddity.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    function Show-ThisPsOddity {
    param(
    [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()][ValidateSet("foo", "bar", "baz", "match")][String]$UserInput,
    [ValidateRange(1,2)][int]$Variant = 1
    )

    switch($variant) {

    1 { if($UserInput -eq "match"){ $UserInput = @("foo", "bar", "baz") } }

    2 { if($UserInput -eq "match"){ [array]$UserInput = "foo", "bar", "baz" } }

    }

    "Before the loop `$UserInput is a $(if($UserInput -is [array]){$UserInput.GetType().BaseType}else{$UserInput.GetType()})"

    foreach($item in $UserInput) { "In the loop `$item is a $(if($item -is [array]){$item.GetType().BaseType}else{$item.GetType()})" }

    }