Skip to content

Instantly share code, notes, and snippets.

View andyloree's full-sized avatar

Andrew Loree andyloree

View GitHub Profile
@andyloree
andyloree / Generate-Password.ps1
Created May 9, 2021 20:47
Generate Random lenght password, using a fixed alphabet
<#
Generates random, complex passwords
#>
function Generate-Password($length)
{
$password = "";
# Removed similar characters: i, l, o, O, 0, 1, I
$alphabet= "abcdefghjkmnpqstuvwxyz23456789ABCDEFGHJKMNPQRSTUVWXYZ!@#$%^&*()"
$char = for ($i = 0; $i -lt $alphabet.length; $i++) { $alphabet[$i] }
@andyloree
andyloree / Execute-CommandWithRetry.ps1
Created May 9, 2021 20:46
Using closures in PowerShell, wrapp any command with retry or common exception handling
function Execute-CommandWithRetry($Command, $CommandName) {
$currentRetry = 0;
$success = $false;
do {
try
{
& $Command;
$success = $true;
Log-Debug "Successfully executed [$CommandName] command. Number of entries: $currentRetry";
}
@andyloree
andyloree / Validate-EmailAddress.ps1
Created May 9, 2021 20:44
Valide email address is wellformed
<#
Does an syntax check for well formed email address
#>
function Valid-EmailAddress($address)
{
try
{
$results = New-Object System.Net.Mail.MailAddress($address)
return $true
}
@andyloree
andyloree / Send-ToGotify_OneLiner.ps1
Created May 4, 2021 20:29
PowerShell one-liner send to Gotify
$message="YOUR_MESSAGE";$title="YOUR_TITLE";$token="YOUR_APP_TOKEN";$uri = "https://your_gotify_service/message?token=$($token)";$body = @{ message = "$($message)"; title = "$($title)"; priority = 3};Invoke-RestMethod -Uri $uri -Method Post -Body $body