Skip to content

Instantly share code, notes, and snippets.

@45413
45413 / Get-HMACHash.ps1
Last active February 1, 2023 05:21
Generate and HMAC Hash in powershell using any supported algorithm (MD5, SHA1, SHA256, SHA384, SHA512)
function Get-HMACHash {
[CmdletBinding()]
param (
# Message to geneate a HMAC hash for
[Parameter(Mandatory = $true,
Position = 0,
ParameterSetName = "Default",
ValueFromPipelineByPropertyName = $true)]
[ValidateNotNullOrEmpty()]
[String]
@45413
45413 / Move-AzVmToNewAvailabilitySet.ps1
Created October 10, 2019 02:33
Move Azure VM to a new Availability Set
<#
.SYNOPSIS
Move Azure VM to an Availability Set
.DESCRIPTION
Deallocates and redeploys an Azure VM to move it into a new Availbility Set.
This Will create the Availability Set if not found.
.EXAMPLE
PS C:\> ./Move-AzVmToNewAvailabilitySet.ps1 -resourceGroup "prismrbs-prod-eus-rg" -vmName "di-vm0" -newAvailSetName "di-vmSet"
Explanation of what the example does
.INPUTS
@45413
45413 / Connect-Office365.ps1
Last active June 25, 2019 22:31
Powershell: Office365 Remote Powershell Session Management
function Connect-Office365
{
[CmdletBinding()]
[Alias()]
[OutputType([void])]
Param
(
# Param1 help description
[Parameter(Position=0)]
[string]$username="",
@45413
45413 / Convert-SecureString.ps1
Created June 11, 2019 02:21
Convert SecureString to String
function Convert-SecureString {
[CmdletBinding()]
param (
# SecureString
[Parameter(Mandatory=$true)]
[SecureString]
$SecureString
)
Return ( [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)) )
@45413
45413 / New-XKPasswd.ps1
Created June 11, 2019 02:10
Generate Random Passwords using XKPasswd
<#
.SYNOPSIS
Use XKPasswd.net to generate random passwords
.DESCRIPTION
Use XKPasswd.net and the XKCD strong password algorithm to generate
easy to remember high entropy passwords
.EXAMPLE
# Generate 4 passwords with 4 words each
New-XKPasswd -Count 4 -Words 4
@45413
45413 / Validate-ADUser.ps1
Created June 21, 2018 13:29
Validate the existence of an AD User with powershell
# Check if AD User Exist: Method 1
[bool] (Get-ADUser -Filter {SamAccountName -eq "NonExistingADUser" })
# Check if AD User Exist: Method 2
## supports all valid identity formats
function Test-ADUser {
[CmdletBinding()]
param (
# Identity
[Parameter(Mandatory=$true)]
@45413
45413 / Enumerate-ConsoleColors.ps1
Created April 27, 2018 02:10
Powershell function to enumerate all available console colors - with examples
function Enumerate-ConsoleColors {
[CmdletBinding()]
param (
# Print Example Switch
[Parameter(Mandatory=$false)]
[Alias("Example","ex","print")]
[Switch]
$PrintExamples=$false
)
# Genereate Dummy array of numbers (does not matter that they are sequental)
$array = 1..20
# Get group size
$size = (($array.Count / 5 ))
# Create empty array to populate with multidemensional array
$rules = @()
# For 0 to count of array.
@45413
45413 / string-and-filename-manipulation.ps1
Last active November 14, 2023 22:47
Powershell String and Filename Manipulation
# Working with a [System.IO.FileInfo] Object
## Get file object into variable
PS C:\DATA> $file = Get-ChildItem C:\DATA\test.xls
## Full path name
PS C:\DATA> $file.FullName
C:\DATA\test.xls
## Filename including extension
PS C:\DATA> $file.Name
@45413
45413 / Get-DatabaseDocumentationToHTML.ps1
Created May 2, 2016 22:06
SQL Server Documentation to HTML
param([string]$SQLServerName="localhost")
# Load needed assemblies
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null;
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMOExtended")| Out-Null;
# Simple to function to write html pages
function writeHtmlPage
{
param ($title, $heading, $body, $filePath);