Author: Matthew Dowst

Active DirectoryUser

Check sAMAccountName Requirements

Function Check-sAMAccountName { [CmdletBinding()] [OutputType([string])] param( [parameter(Mandatory=$true)] [string]$ScriptParameters ) # exclude the characters " * + , / : ; < = > ? @ [ \ ] | $excludedChars = 34,42,43,44,47,58,59,60,61,62,63,64,91,92,93,124 $StringBuilder = New-Object System.Text.StringBuilder # split name into Char Array and check each character $sAMAccountName.ToCharArray() | ForEach-Object{ try{ # convert char to ascii decimal $ascii = [byte][char]$_ #...
FunGeneral

PowerShell Timer with Alarm

Function Start-Timer { param( [Parameter(Mandatory=$true)] [int]$seconds, [Parameter(Mandatory=$false)] [switch]$alarm ) $a = $(Get-Date) For($i=1;$i -le $seconds;$i++){ Write-Progress -Activity "$seconds Second Timer" -Status $i -PercentComplete $(($i/$seconds)*100) -id 1 Start-Sleep -Seconds 1 } if($alarm){ For($i=1;$i -le 10;$i++){ [console]::beep(500,300) } } }
Azure

Easily Switch Between Azure Subscriptions and Tenants

$SubscriptionId = "Your-Subscription-Guid" if($(Get-AzureRmContext).Subscription.SubscriptionId -ne $SubscriptionId){ Set-AzureRmContext -SubscriptionId $SubscriptionId -ErrorAction SilentlyContinue if($(Get-AzureRmContext).Subscription.SubscriptionId -ne $SubscriptionId){ Clear-AzureRMContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue Clear-AzureRmDefault -Force -ErrorAction SilentlyContinue $connect = Add-AzureRmAccount -SubscriptionId $SubscriptionId } }