Skip to content

Instantly share code, notes, and snippets.

View thedavecarroll's full-sized avatar
🧑‍💻
Clever Status

Dave Carroll thedavecarroll

🧑‍💻
Clever Status
View GitHub Profile
[cmdletbinding()]
param (
[parameter(parametersetname='test1')]
[switch]$p1,
[parameter(parametersetname='test2')]
[switch]$p2
)
DynamicParam
@jdhitsolutions
jdhitsolutions / ANSIGreeting.ps1
Last active September 23, 2021 01:56
PowerShell Candy - my demo files from the PSPowerHour on 26 May, 2020
#requires -version 7.0
$am = @"
_____ __ __ ___ _ __ ______
/ ___/__ ___ ___/ / / |/ /__ _______ (_)__ ___ _ __ / /__ / _/ _/
/ (_ / _ \ _ \ _ / / /|_/ / _ \/ __/ _ \/ / _ \ _ `/ / // / -_) _/ _/
\___/\___\___\_,_/ /_/ /_/\___/_/ /_//_/_/_//_\_, ( ) \___/\__/_//_/
/___/|/
"@
@Jaykul
Jaykul / ToDictionary.ps1
Created October 21, 2019 22:54
More LINQ Helpers for PowerShell
# Add a .ToDictionary(KeyType,ValueType) for all hashtables
Update-TypeData -TypeName Hashtable -MemberType ScriptMethod -MemberName ToDictionary -Value {
param([Type]$KeyType,[Type]$ValueType)
[Scriptblock]::Create(
"[Enumerable]::ToDictionary(
[DictionaryEntry[]]@(`$this.GetEnumerator()),
[Func[DictionaryEntry,$($KeyType.FullName)]]{ `$args.Key },
[Func[DictionaryEntry,$($ValueType.FullName)]]{ `$args.Value })"
).Invoke()
}
$crypto = @"
P k T r 2 s z 2 * c F -
r a z 7 G u D 4 w 6 U #
g c t K 3 E @ B t 1 a Y
Q P i c % 7 0 5 Z v A e
W 6 j e P R f p m I ) H
y ^ L o o w C n b J d O
S i 9 M b e r # ) i e U
* f 2 Z 6 M S h 7 V u D
5 a ( h s v 8 e l 1 o W
@potatoqualitee
potatoqualitee / mentalhealth.txt
Last active November 7, 2024 15:33
⛔ BlueSky mental health mute list
# mute here: https://bsky.app/moderation
election
president-elect
hurricane
storm surge
climate crisis
Iran
Israel
ballistic missiles
North Korea
@mklement0
mklement0 / Time-Command.ps1
Last active December 18, 2024 07:42
PowerShell function that times the execution of one or more commands, averaged over a specifiable number of runs.
<#
Prerequisites: PowerShell v5.1 and above (verified; may also work in earlier versions)
License: MIT
Author: Michael Klement <mklement0@gmail.com>
DOWNLOAD and DEFINITION OF THE FUNCTION:
irm https://gist.github.com/mklement0/9e1f13978620b09ab2d15da5535d1b27/raw/Time-Command.ps1 | iex

Credit: Mark Kraus
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.
@Jaykul
Jaykul / ValidateUnique.md
Last active May 7, 2022 01:13
Validating PowerShell class properties

The simplest way to enforce rules on PowerShell class properties is to set the Type of the property, of course. But sometimes you want something a little bit more clever than that. One solution is to use a Validate* attribute, like ValidateRange or ValidateLength or ValidateSet attribute...

However, you can write your own, by just deriving from ValidateArguments() or something that derives from that, like the ValidateEnumeratedArguments class allows you to validate a whole array of items.

For instance, a simple validator would be one that validates uniqueness, based on a specific property. Our validator will be created fresh each time it's used, and then each item in the array will be passed through ValidateElement, so this works:

using namespace System.Collections.Generic
usin
@jdhitsolutions
jdhitsolutions / New-GithubGist.ps1
Last active March 16, 2023 11:53
A PowerShell script to create a new gist on Github.
#requires -version 4.0
Function New-GitHubGist {
[cmdletbinding(SupportsShouldProcess,DefaultParameterSetName = "Content")]
Param(
[Parameter(Position = 0, Mandatory, HelpMessage = "What is the name for your gist?",ValueFromPipelineByPropertyName)]
[ValidateNotNullorEmpty()]
[string]$Name,