This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Start-RunspaceJob { | |
<# | |
.SYNOPSIS | |
It runs a command on a timer, so it can abort the command if the timeout expires. | |
It can also run the command as a different user. | |
It allows the end-user to pass input parameters to the command. | |
.EXAMPLE | |
Start-RunspaceJob -Scriptblock { | |
$p1 = ' ' * 9 ; $p2 = ' ' * 18 | |
Write-Verbose "$p1 1 [V] Will do A" -Verbose |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-AmazonApiOperation { | |
<# | |
.SYNOPSIS | |
Show the relevant AWS API Operation for a given PowerShell command | |
.DESCRIPTION | |
This function comes handy when writing permissions for IAM roles. | |
Because you need to know the actions (as-in API operations) that you want to allow in the IAM policy. | |
.EXAMPLE | |
Get-Command -Noun EC2Tag | Get-AmazonApiOperation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Test-PasswordComplexity { | |
<# | |
.SYNOPSIS | |
It checks if a password meets the minimum required password complexity | |
.EXAMPLE | |
Test-PasswordComplexity -Password 123asdASD -MinComplex 2 -MinLength 6 -MinUpper 2 -MinLower 2 -MinDigits 2 -MinSpecial 2 | |
Returns True. Because the password is more than 6 characters long. It is actually 9 characters long. | |
And it has more than 2 different character types. Namely it has lower, upper and numbers which are 3 different types. | |
And out of those character types is has the minimum number of characters required for each type. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Split-ByGroup { | |
<# | |
.SYNOPSIS | |
It will split an array into chunks and return a number of arrays based on a group size | |
.EXAMPLE | |
# first create a sample array (I'm using the RNG class here to do that) | |
$ArraySize = 160 | |
$Array = [byte[]]::new($ArraySize) | |
$rng = [Security.Cryptography.RandomNumberGenerator]::Create() | |
$rng.GetBytes($Array) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Disable-WingetPinning { | |
<# | |
.SYNOPSIS | |
It disables the Certificate Pinning option in WinGet for the MS Store source. | |
This is usually required when there is a firewall on your network that inspects SSL traffic, | |
where you might get an error 0x8a15005e back from WinGet, as it cannot access the msstore endpoint URL. | |
.DESCRIPTION | |
If you are behind a firewall that inspects SSL traffic, | |
that means it decrypts & re-encrypts traffic on the fly in order to inspect it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# How to make a custom type sortable | |
# There are 2 ways to make a type sortable | |
# | |
# 1) you can inherit from the IComparable interface [System.IComparable] | |
# where you will compare based on a predefined property of the object | |
# and you need to implement the CompareTo() method | |
# | |
# 2) you can create a custom Comparer type that will inherit from the IComparer interface [System.Collections.Generic.IComparer[T]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# change this Enum with your actual accounts and their IDs | |
enum NewRelicAccountName { | |
NRAcc1 = 300000 | |
NRAcc2 = 400000 | |
NRAcc3 = 500000 | |
NRAcc4 = 600000 | |
} | |
function Get-NRMonitor { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-DurationText { | |
<# | |
.SYNOPSIS | |
Get the elapsed duration as a string, in a number of different formats | |
.EXAMPLE | |
Get-DurationText -Duration ([timespan]::FromDays(2)) | |
2d 0hr | |
#> | |
[CmdletBinding(DefaultParameterSetName='Timespan')] | |
[OutputType([string])] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I wrote these notes in Sep-2024 | |
# AES 128 and 256 bits | |
# Without using .NET Streams | |
## Initial Input | |
[string]$PlainText = 'this is a test message' | |
[string]$Password = 'SampleSecret' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-ArgumentCompleter { | |
<# | |
.SYNOPSIS | |
Get the argument completers that are registered in the current session (if any) | |
.EXAMPLE | |
Import-Module PowerShellGet | |
Get-ArgumentCompleter | |
shows the argument completers that are registered from the PowerShellGet module | |
.EXAMPLE |
NewerOlder