Skip to content

Instantly share code, notes, and snippets.

View ChrisLGardner's full-sized avatar

Chris Gardner ChrisLGardner

View GitHub Profile
@ChrisLGardner
ChrisLGardner / Find-Dependencies.ps1
Created September 13, 2018 14:14 — forked from Jaykul/Trace-Dependency.ps1
Extract module dependency information from a script. **Note**: will show errors for commands not available on your system.
#requires -Module Reflection
function Find-Dependencies {
param($Path)
Get-ParseResults $Path |
Find-Token { $_ -is "System.Management.Automation.Language.CommandAst" } |
Get-Command -Name { $_.CommandElements[0].Value } -ea continue | # Errors will appear for commands you don't have available
Sort Source, Name |
Group Source |
Select @{N="Module";e={$_.Name}}, @{N="Used Commands";E={$_.Group}}

Credit: Mark Krauss
Website: https://get-powershellblog.blogspot.com

Collection Type Guidence

When to use what

  • Use Arrays if you know the element types and have a fixed length and/or known-up-front collection size that will not change.
  • Use ArrayList if you have an unkown collection size with either unknown or mixed type elements.
  • Use a Generic List when know the type of the elements but not the size of the collection.
  • Use a HashTable if you are going to do key based lookups on a collection and don't know the object type of the elements.
  • Use a Dictionary<TKey, TValue> you are going to do key based lookups on a collection and you know the type of the elements.
  • Use a HashSet when you know the type of elements and just want unique values and quick lookups and assignmnets.
@ChrisLGardner
ChrisLGardner / Hide-FromDebugger.ps1
Created July 31, 2017 08:19 — forked from Jaykul/Hide-FromDebugger.ps1
Have you ever wished you could hide a few commands from the PowerShell step-through?
<#
.SYNOPSIS
Wrap commands with DebuggerNonUserCode attribute to prevent the PowerShell debugger stepping into them
.DESCRIPTION
Generates proxy functions that wrap the original commands, and put an attribute on the proxy to prevent the debugger stopping.
.EXAMPLE
Get-Command -Module Pester | Hide-FromDebugger
Hides all pester functions from the debugger, so you can debug in your code without stepping into Pester functions.
#>