Skip to content

Instantly share code, notes, and snippets.

View ChrisLGardner's full-sized avatar

Chris Gardner ChrisLGardner

View GitHub Profile
$arr = @("25.02.2020 10:11:58"
"25.02.2020 10:12:21"
"25.02.2020 11:03:37"
"25.02.2020 11:03:37"
"25.02.2020 11:35:28"
"25.02.2020 11:35:32"
"25.02.2020 12:40:03"
"25.02.2020 14:08:11"
"25.02.2020 14:09:49"
"25.02.2020 14:39:44"
function test-switch {
param (
[switch]$switch1,
[switch]$switch2,
[switch]$switch3,
[switch]$switch4
)
switch ($true) {
$switch1 { "test1" }
function get-stuff {
param (
[ValidateSet('A','b','c','d')]
[string]$user,
[ValidateNotNullOrEmpty()]
[string]$data
)
}
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.
################
### Rollback ###
################
# Use with : './apply_oracle_secpatch.bat -rollback'
Function rollback
{
Param
(
[Parameter()]
[switch]$rollback
using Namespace System.Management.Automation.Language
Function Get-AliasTarget {
[cmdletbinding()]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[Alias('PSPath', 'FullName')]
[string[]]$Path
)
@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}}
[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
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
}
}
}

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.