Skip to content

Instantly share code, notes, and snippets.

@ekmixon
Forked from daephx/Format-Relative.ps1
Created October 4, 2021 18:11

Revisions

  1. @daephx daephx revised this gist Aug 15, 2021. No changes.
  2. @daephx daephx revised this gist Jul 11, 2021. No changes.
  3. @daephx daephx revised this gist Jul 11, 2021. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions Show-Confirmation.ps1
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    <#
    .SYNOPSIS
    Prompt user for [y/n] confirmation.
    .NOTES
    * Consider:
    If a cmdlet supports the -confirm parameter, it can be forced to prompt before any action.
    I just like version #1 because it's concise.
    .SYNOPSIS
    Prompt user for [y/n] confirmation.
    .NOTES
    * Consider:
    If a cmdlet supports the -confirm parameter, it can be forced to prompt before any action.
    I just like version #1 because it's concise.
    #>

    # Version #1
    @@ -21,6 +21,6 @@ $Choices = [System.Management.Automation.Host.Choicedescription[]]($Yes, $No)
    $Answer = $Host.Ui.Promptforchoice($Caption, $Message, $Choices, 0)

    Switch ($Answer) {
    0 { "You Entered 0"; Break }
    1 { "You Entered 1"; Break }
    }
    0 { "You Entered 0"; Break }
    1 { "You Entered 1"; Break }
    }
  4. @daephx daephx revised this gist Aug 24, 2020. No changes.
  5. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ Write-Host (Get-Help $PSCommandPath).Synopsis -ForegroundColor DarkGray

    $Loop = 10000

    # Static Array Size
    # Static Array
    $Measure_Array = Measure-Command {
    $array = @()
    1..$Loop | ForEach-Object { $array += "$_" }
  6. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ $Measure_Array = Measure-Command {
    1..$Loop | ForEach-Object { $array += "$_" }
    }

    #
    # Generic List
    $Measure_List = Measure-Command {
    $list = [System.Collections.Generic.List[string]]::new()
    1..$Loop | ForEach-Object { $null = $list.Add("$_") }
  7. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,7 @@ $Measure_Array = Measure-Command {
    1..$Loop | ForEach-Object { $array += "$_" }
    }


    #
    $Measure_List = Measure-Command {
    $list = [System.Collections.Generic.List[string]]::new()
    1..$Loop | ForEach-Object { $null = $list.Add("$_") }
  8. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -24,6 +24,7 @@ $Measure_Array = Measure-Command {
    1..$Loop | ForEach-Object { $array += "$_" }
    }


    $Measure_List = Measure-Command {
    $list = [System.Collections.Generic.List[string]]::new()
    1..$Loop | ForEach-Object { $null = $list.Add("$_") }
  9. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ Write-Host (Get-Help $PSCommandPath).Synopsis -ForegroundColor DarkGray

    $Loop = 10000

    # Static Array
    # Static Array Size
    $Measure_Array = Measure-Command {
    $array = @()
    1..$Loop | ForEach-Object { $array += "$_" }
  10. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ Write-Host (Get-Help $PSCommandPath).Synopsis -ForegroundColor DarkGray

    $Loop = 10000

    # Fixed Array
    # Static Array
    $Measure_Array = Measure-Command {
    $array = @()
    1..$Loop | ForEach-Object { $array += "$_" }
  11. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ Write-Host (Get-Help $PSCommandPath).Synopsis -ForegroundColor DarkGray

    $Loop = 10000

    #
    # Fixed Array
    $Measure_Array = Measure-Command {
    $array = @()
    1..$Loop | ForEach-Object { $array += "$_" }
  12. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -18,6 +18,7 @@ Write-Host (Get-Help $PSCommandPath).Synopsis -ForegroundColor DarkGray

    $Loop = 10000

    #
    $Measure_Array = Measure-Command {
    $array = @()
    1..$Loop | ForEach-Object { $array += "$_" }
  13. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ $Measure_List = Measure-Command {
    }


    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"
    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())`n"

    Write-Host "'Array +='`t: " -NoNewline
    Write-Host "Milliseconds: $($Measure_Array.TotalMilliseconds)"
  14. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ $Measure_List = Measure-Command {

    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"

    Write-Host "`n'Array +='`t: " -NoNewline
    Write-Host "'Array +='`t: " -NoNewline
    Write-Host "Milliseconds: $($Measure_Array.TotalMilliseconds)"

    Write-Host "'List.Add()'`t: " -NoNewline
  15. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,8 @@ $Measure_List = Measure-Command {


    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"
    Write-Host "`nArray +='`t: " -NoNewline

    Write-Host "`n'Array +='`t: " -NoNewline
    Write-Host "Milliseconds: $($Measure_Array.TotalMilliseconds)"

    Write-Host "'List.Add()'`t: " -NoNewline
  16. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ $Measure_List = Measure-Command {


    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"
    Write-Host "`n'Array +='`t: " -NoNewline
    Write-Host "`nArray +='`t: " -NoNewline
    Write-Host "Milliseconds: $($Measure_Array.TotalMilliseconds)"

    Write-Host "'List.Add()'`t: " -NoNewline
  17. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ $Measure_List = Measure-Command {


    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"
    Write-Host "`nArray +='`t: " -NoNewline
    Write-Host "`n'Array +='`t: " -NoNewline
    Write-Host "Milliseconds: $($Measure_Array.TotalMilliseconds)"

    Write-Host "'List.Add()'`t: " -NoNewline
  18. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,7 @@ $Measure_List = Measure-Command {


    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"
    Write-Host "`n'Array +='`t: " -NoNewline
    Write-Host "`nArray +='`t: " -NoNewline
    Write-Host "Milliseconds: $($Measure_Array.TotalMilliseconds)"

    Write-Host "'List.Add()'`t: " -NoNewline
  19. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -30,7 +30,6 @@ $Measure_List = Measure-Command {


    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"
    ""
    Write-Host "`n'Array +='`t: " -NoNewline
    Write-Host "Milliseconds: $($Measure_Array.TotalMilliseconds)"

  20. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,7 @@ $Measure_List = Measure-Command {

    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"
    ""
    Write-Host "'Array +='`t: " -NoNewline
    Write-Host "`n'Array +='`t: " -NoNewline
    Write-Host "Milliseconds: $($Measure_Array.TotalMilliseconds)"

    Write-Host "'List.Add()'`t: " -NoNewline
  21. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -28,7 +28,7 @@ $Measure_List = Measure-Command {
    1..$Loop | ForEach-Object { $null = $list.Add("$_") }
    }

    ""

    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"
    ""
    Write-Host "'Array +='`t: " -NoNewline
  22. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -29,7 +29,7 @@ $Measure_List = Measure-Command {
    }

    ""
    Write-Host "PS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"
    Write-Host "`nPS $($PSVersionTable.PSEdition) $($PSVersionTable.PSVersion.ToString())"
    ""
    Write-Host "'Array +='`t: " -NoNewline
    Write-Host "Milliseconds: $($Measure_Array.TotalMilliseconds)"
  23. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    PowerShell is then executing the old one, and I’m talking capital punishment here.
    The old array is no more and you are left with its blood on your hands.
    .LINK
    Tanks: https://theposhwolf.com/howtos/PS-Plus-Equals-Dangers/
    Thanks: https://theposhwolf.com/howtos/PS-Plus-Equals-Dangers/
    #>

    # Breifly introduce the current running script.
  24. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    PowerShell is then executing the old one, and I’m talking capital punishment here.
    The old array is no more and you are left with its blood on your hands.
    .LINK
    https://theposhwolf.com/howtos/PS-Plus-Equals-Dangers/
    Tanks: https://theposhwolf.com/howtos/PS-Plus-Equals-Dangers/
    #>

    # Breifly introduce the current running script.
  25. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,11 @@
    https://theposhwolf.com/howtos/PS-Plus-Equals-Dangers/
    #>

    # Breifly introduce the current running script.
    Write-Host "`n" ($MyInvocation.ScriptName)
    # Get-Help wont work if script starts with function...
    Write-Host (Get-Help $PSCommandPath).Synopsis -ForegroundColor DarkGray

    $Loop = 10000

    $Measure_Array = Measure-Command {
  26. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions Test-AppendPerformance.ps1
    Original file line number Diff line number Diff line change
    @@ -14,13 +14,13 @@
    $Loop = 10000

    $Measure_Array = Measure-Command {
    $array = @()
    1..$Loop | ForEach-Object { $array += "$_" }
    $array = @()
    1..$Loop | ForEach-Object { $array += "$_" }
    }

    $Measure_List = Measure-Command {
    $list = [System.Collections.Generic.List[string]]::new()
    1..$Loop | ForEach-Object { $null = $list.Add("$_") }
    $list = [System.Collections.Generic.List[string]]::new()
    1..$Loop | ForEach-Object { $null = $list.Add("$_") }
    }

    ""
  27. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-PipelineSpeed.ps1
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ function Test-RandomInputObjectBenchmark {

    # Run the Test-Functions
    Write-Host "$('-'*80)" -ForegroundColor DarkGray # Seperator
    write-host "Running: Benchmark #1 [Pipeline]"
    Write-Host "Running: Benchmark #1 [Pipeline]"
    Test-RandomPipelineBenchmark
    Write-Host "$('-'*80)" -ForegroundColor DarkGray # Seperator
    Write-Host "Running: Benchmark #1 [InputObject]"
  28. @daephx daephx revised this gist Aug 24, 2020. No changes.
  29. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Test-PipelineInput.ps1
    Original file line number Diff line number Diff line change
    @@ -9,9 +9,9 @@
    #>

    # Breifly introduce the current running script.
    Write-Host ($MyInvocation.ScriptName)
    Write-Host "`n" ($MyInvocation.ScriptName)
    # Get-Help wont work if script starts with function...
    Write-Host "`n" (Get-Help $PSCommandPath).Synopsis
    Write-Host (Get-Help $PSCommandPath).Synopsis -ForegroundColor DarkGray

    Function Test-PipelineInput {

  30. @daephx daephx revised this gist Aug 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Test-PipelineSpeed.ps1
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    # Breifly introduce the current running script.
    Write-Host "`n" ($MyInvocation.ScriptName)
    # Get-Help wont work if script starts with function...
    Write-Host (Get-Help $PSCommandPath).Synopsis
    Write-Host (Get-Help $PSCommandPath).Synopsis -ForegroundColor DarkGray

    function Test-RandomPipelineBenchmark {