Skip to content

Instantly share code, notes, and snippets.



Last active Sep 2, 2020
What would you like to do?
Powershell Aides-Mémoire
#Creating a pscredential from a username:password pair in a single line:
$Creds = New-Object System.Management.Automation.PSCredential ($User, $(ConvertTo-SecureString $Password -AsPlainText -Force))
#Self signed wildcard certificate
New-SelfSignedCertificate -Subject *.my.domain -DnsName my.domain, *.my.domain -CertStoreLocation Cert:\LocalMachine\My -NotAfter (Get-Date).AddYears(10)
# trusting the PS gallery so we can install packages unattended, e.g. for DSC
Install-PackageProvider NuGet -Force -Scope CurrentUser
Import-PackageProvider NuGet -Force
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
#generating Random String
# source:
$someRandomLetters = -join ((65..90) + (97..122) | Get-Random -Count 20 | % {[char]$_})
#Generating an ARM-style UniqueString
# source:
function Get-UniqueString ([string]$id, $length=13)
$hashArray = (new-object System.Security.Cryptography.SHA512Managed).ComputeHash($id.ToCharArray())
-join ($hashArray[1..$length] | ForEach-Object { [char]($_ % 26 + [byte][char]'a') })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment