Skip to content

Instantly share code, notes, and snippets.

View thedavecarroll's full-sized avatar
🧑‍💻
PowerShell Summit

Dave Carroll thedavecarroll

🧑‍💻
PowerShell Summit
View GitHub Profile
@AndySchneiderDev-zz
AndySchneiderDev-zz / Update-Schema.ps1
Last active June 19, 2018 18:55
PowerShell to Udpate Active Directory Schema
# This should only be used in a development environment and is for demonstration purposes only
# Use at your own risk
# This adds an attribute to the user class
# Written by Andy Schneider, http://get-powershell.com
Function New-OID {
$Prefix="1.2.840.113556.1.8000.2554"
$GUID=[System.Guid]::NewGuid().ToString()
$Parts=@()
$Parts+=[UInt64]::Parse($guid.SubString(0,4),"AllowHexSpecifier")
$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
[cmdletbinding()]
param (
[parameter(parametersetname='test1')]
[switch]$p1,
[parameter(parametersetname='test2')]
[switch]$p2
)
DynamicParam
@jdhitsolutions
jdhitsolutions / SendTo-Gist.ps1
Last active November 13, 2020 18:06
A PowerShell ISE script to send selected text as a Github gist. This requires my New-GitHubGist function.
#requires -version 4.0
#dot source the script with the New-GitHubGist function
. C:\scripts\New-GitHubGist.ps1
Function SendTo-Gist {
[cmdletbinding()]
Param(
[Parameter(Position = 0)]
[ValidateNotNullorEmpty()]
@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()
}
@potatoqualitee
potatoqualitee / mentalhealth.txt
Last active July 8, 2021 13:07
⛔ Twitter mental health mute list
# mute here: https://twitter.com/settings/muted_keywords
republicans
democrats
sanders
manafort
comey
koch
kkk
ku klux klan
TERF
@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 / 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
@stevenkuhn
stevenkuhn / gist:5062660
Last active March 7, 2023 16:03
This PowerShell script generates release notes for Octopus Deploy that contain the GitHub commits and JIRA issues from the current build to the latest production release. It will also create the Octopus release based on the TeamCity build number.
#
# Assumptions
#
# 1. If you have a Octopus release deployed, say 1.0.0.73, there is a git
# tag set for that commit in GitHub that is "v1.0.0.73".
#
# 2. You have TeamCity label each successful build in GitHub with the format
# "v{build number}. Sidenote: it appears that TeamCity only labels the
# default branch, but not feature branches.
#
@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,