Skip to content

Instantly share code, notes, and snippets.

@alimbada
alimbada / Wake.ps1
Last active June 18, 2025 15:18
PowerShell script for sending Wake On LAN magic packets to given machines/MAC address(es)
#######################################################
##
## Wake.ps1, v1.0, 2013
##
## Adapted by Ammaar Limbada
## Original Author: Matthijs ten Seldam, Microsoft (see: http://blogs.technet.com/matthts)
##
#######################################################
<#
@WalternativE
WalternativE / compute-sha-256-hash.ps1
Created March 28, 2017 07:18
Powershell script that returns SHA-256 hash for a given string
Param (
[Parameter(Mandatory=$true)]
[string]
$ClearString
)
$hasher = [System.Security.Cryptography.HashAlgorithm]::Create('sha256')
$hash = $hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($ClearString))
$hashString = [System.BitConverter]::ToString($hash)
@indented-automation
indented-automation / New-Password.ps1
Last active May 7, 2024 08:57
PowerShell random password generator.
function New-Password {
<#
.SYNOPSIS
Generate a random password.
.DESCRIPTION
Generate a random password.
.NOTES
Change log:
27/11/2017 - faustonascimento - Swapped Get-Random for System.Random.
Swapped Sort-Object for Fisher-Yates shuffle.
@jakobii
jakobii / HTTPServer.ps1
Last active May 4, 2024 14:02
A Basic Powershell Webserver
# You Should be able to Copy and Paste this into a powershell terminal and it should just work.
# To end the loop you have to kill the powershell terminal. ctrl-c wont work :/
# Http Server
$http = [System.Net.HttpListener]::new()
# Hostname and port to listen on
$http.Prefixes.Add("http://localhost:8080/")

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.
@dalion619
dalion619 / SubjectAlternativeNames
Created August 20, 2018 08:58
X509Certificate2 Subject Alternative Names Extension Method
public static List<string> GetSubjectAlternativeNames(this X509Certificate2 certificate)
{
foreach (X509Extension extension in certificate.Extensions)
{
// Create an AsnEncodedData object using the extensions information.
AsnEncodedData asndata = new AsnEncodedData(extension.Oid, extension.RawData);
if (string.Equals(extension.Oid.FriendlyName, "Subject Alternative Name"))
{
//Console.WriteLine("Extension type: {0}", extension.Oid.FriendlyName);
//Console.WriteLine("Oid value: {0}", asndata.Oid.Value);
@kpatnayakuni
kpatnayakuni / Demo-Choices.ps1
Last active April 16, 2025 18:39
Prompt for choice in PowerShell
# PromptForChoice Args
$Title = "Do you want to proceed further?"
$Prompt = "Enter your choice"
$Choices = [System.Management.Automation.Host.ChoiceDescription[]] @("&Yes", "&No", "&Cancel")
$Default = 1
# Prompt for the choice
$Choice = $host.UI.PromptForChoice($Title, $Prompt, $Choices, $Default)
# Action based on the choice
@andyraddatz
andyraddatz / ASCIIStringExtensions.cs
Last active May 27, 2025 07:35
C# String extension method to fold diacritics to ASCII characters
// IMPORTANT
using System.Text;
// This gist was created thanks to this comment from Alexander on StackOverflow:
// https://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net#comment86833005_34272324
// This is a derivative work. The logic of this function comes from a switch statement found inside the
// Lucene.Net library. The documentation of the conversion of characters is quite impressive
// (thank you @NightOwl888 and @synhershko !!!):
// https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/ASCIIFoldingFilter.cs
@yon2004
yon2004 / AD-BASE64-SID.ps1
Last active May 28, 2025 07:42
Convert AD BASE64 SID to SDDL format and back.
#Convert from Base64 to SID
[byte[]]$sid = [System.Convert]::FromBase64String("AQUAAAAAAAUVAAAAuwkCIyAUg1vk+E/VWQQAAA==")
$si = New-Object Security.Principal.SecurityIdentifier($sid,0)
$si.ToString()
#Convert from SID to Base64 (Needed for squid)
$sidconvert = New-Object Security.Principal.SecurityIdentifier("S-1-5-21-587336123-1535317024-3578788068-1112")
$sid_out = New-Object 'byte[]' $sidconvert.BinaryLength
$sidconvert.GetBinaryForm($sid_out,0)
@jpluimers
jpluimers / README.md
Last active March 8, 2025 01:24 — forked from alimbada/Wake.ps1
Wake-on-LAN.ps1 PowerShell script for sending Wake-on-LAN magic packets to given machine's hardware MAC address

Wake-on-LAN.ps1: a Wake-on-LAN PowerShell script

Wake-on-LAN.ps1 PowerShell script for sending Wake-on-LAN magic packets to given machine's hardware MAC address

This script originated is a modification [Wayback] WakeUp-Machines.ps1 by Matthijs ten Seldam, Microsoft that has the drawback of requiring a text file with the machines to wake up, and (before his change) the original reliance on the above mentioned [Wayback] WolCmd.exe in the current directory.

[[Wayback]](https://web.archive.org/web/2021