Skip to content

Instantly share code, notes, and snippets.

View ChrisLGardner's full-sized avatar

Chris Gardner ChrisLGardner

View GitHub Profile
@ChrisLGardner
ChrisLGardner / Randomfile.json
Created March 30, 2016 14:16
Xml file pushed to convertto-json
[
[
],
[
],
[
[
"System.Xml.XmlElement",
@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.
#>

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.
describe "doing some testing" {
Get-Command -Module TunableSSLValidator | % {
It "Should not have any conflicting names for $($_.Name) function" {
(Get-Command $_.Name -All).count | Should -Not -BeGreaterThan 1
}
}
}
[cmdletbinding()]
param (
$SourceFolder = $PSScriptRoot
)
if (-not (Get-Module PSDepend -ListAvailable)) {
Install-Module PSDepend -Repository (Get-PSRepository)[0].Name -Scope CurrentUser
}
Push-Location $PSScriptRoot -StackName BuildScript
Invoke-PSDepend -Path $SourceFolder -Confirm:$false
@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}}
using Namespace System.Management.Automation.Language
Function Get-AliasTarget {
[cmdletbinding()]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[Alias('PSPath', 'FullName')]
[string[]]$Path
)
################
### Rollback ###
################
# Use with : './apply_oracle_secpatch.bat -rollback'
Function rollback
{
Param
(
[Parameter()]
[switch]$rollback
function New-ModuleOverview {
<#
.SYNOPSIS
Generates a Markdown file with a short description of each public command in a module.
.DESCRIPTION
Finds all the public commands in a specified module and produces a simple Markdown file detailing the description or synopsis (user choice) for each.
.PARAMETER ModuleName
Name of the module to generate an overview for. If the module isn't already loaded then it will be loaded.
function get-stuff {
param (
[ValidateSet('A','b','c','d')]
[string]$user,
[ValidateNotNullOrEmpty()]
[string]$data
)
}