Skip to content

Instantly share code, notes, and snippets.

View JeremyTBradshaw's full-sized avatar
🤠
Yeehaw

Jeremy JeremyTBradshaw

🤠
Yeehaw
View GitHub Profile
@JeremyTBradshaw
JeremyTBradshaw / New-Password.ps1
Last active April 13, 2023 01:02
PowerShell Password Generator
<#
.Synopsis
Generate one or more random passwords, from 7 to 64 characters in length.
.Description
Passwords are generated using an equal distribution of upper and lower case letters, numbers, space, and special
characters found on the number row.
.Parameter Length
Specifies the length of the generated password(s).
@JeremyTBradshaw
JeremyTBradshaw / GuidToImmutableIdAndBack.ps1
Last active July 27, 2022 14:13
Convert between Guid and ImmutableId (for Azure AD / Office 365 customers)
#Requires -Version 3
function ConvertFrom-GuidToImmutableId ([Guid]$Guid){
[System.Convert]::ToBase64String([Guid]::Parse($Guid).ToByteArray())
}
New-Alias -Name g2i -Value ConvertFrom-GuidToImmutableId
function ConvertFrom-ImmutableIdToGuid ([string]$ImmutableId) {
#Requires -Version 5.1
using namespace System.Management.Automation.Host
switch (
$host.UI.PromptForChoice(
"Caption (e.g. 'XYZ has come up!')",
"Message (e.g. 'How would you like to proceed?",
[ChoiceDescription[]]@(
@JeremyTBradshaw
JeremyTBradshaw / ConvertFrom-SecureStringToPlainText.ps1
Last active January 30, 2023 09:30
For PowerShell 5.1 and older, convert secure strings back to plain text
function ConvertFrom-SecureStringToPlainText ([System.Security.SecureString]$SecureString) {
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto(
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)
)
}
New-Alias -Name s2p -Value ConvertFrom-SecureStringToPlainText
@JeremyTBradshaw
JeremyTBradshaw / New-FakeThumbprint.ps1
Last active December 3, 2020 17:34
Quick fake certificate thumbprints (and Guid's)
# For documentation purposes, sometimes I need fake thumbprints (and Guid's).
function New-FakeThumbprint ([ValidateRange(1, 10)][int]$Count = 1) {
1..$Count | ForEach-Object {
(
1..40 | Foreach-Object {
Get-Random @('A', 'B', 'C', 'D', 'E', 'F', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
}
) -join ''
reg add HKCU\Software\Microsoft\Office\16.0\Outlook\AutoDiscover /v PreferLocalXML /t REG_DWORD /d 0
reg add HKCU\Software\Microsoft\Office\16.0\Outlook\AutoDiscover /v ExcludeHttpRedirect /t REG_DWORD /d 0
reg add HKCU\Software\Microsoft\Office\16.0\Outlook\AutoDiscover /v ExcludeHttpsAutoDiscoverDomain /t REG_DWORD /d 0
reg add HKCU\Software\Microsoft\Office\16.0\Outlook\AutoDiscover /v ExcludeHttpsRootDomain /t REG_DWORD /d 0
reg add HKCU\Software\Microsoft\Office\16.0\Outlook\AutoDiscover /v ExcludeScpLookup /t REG_DWORD /d 0
reg add HKCU\Software\Microsoft\Office\16.0\Outlook\AutoDiscover /v ExcludeSrvRecord /t REG_DWORD /d 0
reg add HKCU\Software\Microsoft\Office\16.0\Outlook\AutoDiscover /v ExcludeLastKnownGoodURL /t REG_DWORD /d 0
reg add HKCU\Software\Microsoft\Office\16.0\Outlook\AutoDiscover /v ExcludeExplicitO365Endpoint /t REG_DWORD /d 0
@JeremyTBradshaw
JeremyTBradshaw / Exchange_pre-CU_Backup.ps1
Created March 5, 2021 00:44
Exchange pre-CU Backup
# Backup all *.config files.
# Backup all supported OWA customization files:
# https://docs.microsoft.com/en-us/Exchange/clients/outlook-on-the-web/customize-outlook-on-the-web?view=exchserver-2016
# https://docs.microsoft.com/en-us/Exchange/clients/outlook-on-the-web/customize-outlook-on-the-web?view=exchserver-2019
$BackupLocation = "$HOME\Desktop\Exchange_pre-CU_Backup\"
$ExInstallRoot = 'C:\Program Files\Microsoft\Exchange Server\v15\'
$OwaAuthDir = '\FrontEnd\HttpProxy\owa\auth\'
$OwaPremDir = '\ClientAccess\Owa\prem\'
using namespace System
using namespace System.Runtime.InteropServices
########-----------#
#region# Variables #
########-----------#
try {
$Cred1 = Import-Clixml "$($HOME)\Cred1.xml" -ErrorAction Stop
Write-Information -MessageData "`$Cred1: $($Cred1.UserName)" -InformationAction Continue
@JeremyTBradshaw
JeremyTBradshaw / Capture-LegacyExchangeDNs.ps1
Created December 16, 2021 19:46
Capture LegacyExchangeDN's during Exchange org splits
<#
.Synopsis
This is not intended to be an executable script. It's PS1 for now simply for syntax highlighting.
#>
#======#---------------------------#
#region# Backup LegacyExchangeDN's #
#======#---------------------------#
$LDNRecipients = @()
$Recipients = @()
@JeremyTBradshaw
JeremyTBradshaw / ConvertFrom-DistinguishedName.ps1
Created August 5, 2022 12:01
Convert DistinguishedName's to CanonicalName's
function ConvertFrom-DistinguishedName ($DistinguishedName) {
$Domain = ($DistinguishedName -split ',DC=' | Where-Object { $_ -notmatch '^CN=' }) -join '.'
$CNPath = ($DistinguishedName -split ',DC=' | Where-Object { $_ -match '^CN=' }) -split ',\w\w='
[array]::Reverse($CNPath)
($Domain + '/' + ($CNPath -join '/')) -replace 'CN=' -replace '\\'
}
ConvertFrom-DistinguishedName "CN=Bradshaw\, Jeremy,OU=PowerShell,DC=Sample,DC=code"