Skip to content

Instantly share code, notes, and snippets.

View mardahl's full-sized avatar
🤓
not afraid to commit!

Michael Mardahl mardahl

🤓
not afraid to commit!
View GitHub Profile
@mardahl
mardahl / invoke-GenerateRandomBitlockerKeys.ps1
Created March 14, 2022 09:07
Generate random bitlocker recovery keys
#Generates 100 random bitlocker recovery key ID and keys
#By Michael Mardahl github.com/mardahl
#Use it for whatever...
$hash = @{}
for($i = 0;$i -lt 100;$i++) {
$id = "$(Get-Random -minimum 100 -maximum 999)$((97..102) | Get-Random -Count 1 | % {[char]$_})$(Get-Random -minimum 100 -maximum 999)$((97..102) | Get-Random -Count 1 | % {[char]$_})-$(Get-Random -minimum 100 -maximum 999)$((97..102) | Get-Random -Count 1 | % {[char]$_})-$(Get-Random -minimum 100 -maximum 999)$((97..102) | Get-Random -Count 1 | % {[char]$_})-$(Get-Random -minimum 100 -maximum 999)$((97..102) | Get-Random -Count 1 | % {[char]$_})-$(Get-Random -minimum 100 -maximum 999)$((97..102) | Get-Random -Count 1 | % {[char]$_})$(Get-Random -minimum 100 -maximum 999)$((97..102) | Get-Random -Count 1 | % {[char]$_})$((97..102) | Get-Random -Count 1 | % {[char]$_})$(Get-Random -minimum 10 -maximum 99)$((97..102) | Get-Random -Count 1 | % {[char]$_})"
$key = "$(Get-Random -minimum 100000 -maximum 999999)-$(Get-Random -minimum 100000 -maximu
@mardahl
mardahl / invoke-BulkDeleteCloudFlareZones.ps1
Last active October 7, 2021 11:46
CloudFlare PowerShell to bulk delete DNS Zones
#license MIT
#Author Michael Mardahl github.com/mardahl
#region declarations
$env:CF_API_KEY = 'axxxxxxxxxxxxxxxxxxxx'
$env:CF_API_EMAIL= 'xxxxxxx@xxxxxx.xxx'
$domains = $(Get-Content .\domains.txt) #text file with 1 domain per line
#endregion declarations
#region execute
@mardahl
mardahl / invoke-BulkAddCloudFlareZones.ps1
Last active April 10, 2024 14:19
CloudFlare powershell to bulk add new DNS Zones
#region declarations
$apikey = 'axxxxxxxxxxxxxxxxx6a4f5bxxxxxxxxxxxxx'
$email = 'xxxxxxxxx@xxxxxxxxx.xxx'
$accountid = 'b6xxxxxxxxxxxxxxxxx8e57xxxx'
$domains = $(Get-Content .\domains.txt) #text file with 1 domain per line
#endregion declarations
#region execute
foreach ($domain in $domains){
$headers = @{
@echo off
REM Description: Small helper script to quickly start an AADSync but just double clicking on this script file.
REM Author: Michael Mardahl - github.com/mardahl
echo Starting AD Sync (Delta)...
powershell.exe -ex bypass -command "ipmo adsync;Start-ADSyncSyncCycle delta;"
echo Finished script execution.
pause
@mardahl
mardahl / export-OutlookProfilesListToCSV.ps1
Created December 18, 2020 16:23
Script to export a list of all Outlook profiles attached to a user in Windows - can be run as login script
#Define central storage for the log files to be collected.
#Make sure all users that run this script have write permissions on this share
$logFile = "\\fileserver.domain.local\share\$($env:USERNAME)_OutlookAccounts.csv"
#Testing for Outlook 2013 and newer
If (Test-Path 'hkcu:\Software\Microsoft\Office\15.0\Outlook\Profiles') {
$regPath = 'hkcu:\Software\Microsoft\Office\15.0\Outlook\Profiles\*\9375CFF0413111d3B88A00104B2A6676\*'
}elseif(Test-Path 'hkcu:\Software\Microsoft\Office\16.0\Outlook\Profiles'){
@mardahl
mardahl / Invoke-O365DKIMEnable.ps1
Last active December 2, 2020 16:40
Enable 2048-bit DKIM in Office 365 script
try{
Connect-ExchangeOnline -ErrorAction Stop
} catch {
Throw "Failed to logon to Exchange Online"
}
$dkim = Get-DkimSigningConfig
foreach($obj in $dkim){
Write-Host "Enabling 2048-bit DKIM for $($obj.Domain)" -ForegroundColor Green
@mardahl
mardahl / Get-O365DKIMDNS.ps1
Created December 2, 2020 11:37
Office 365 DKIM DNS records
#requires -RunAsAdministrator
Set-ExecutionPolicy Bypass -Confirm:$false -Force
Install-Module ExchangeOnlineManagement
Import-Module ExchangeOnlineManagement
try{
Connect-ExchangeOnline -ErrorAction Stop
} catch {
Throw "Failed to logon to Exchange Online"
}
@mardahl
mardahl / gist:8e22c5ca71f95cb616a45f0db36bc78c
Last active October 7, 2020 12:26
Create exchange send connector for relaying through exchange online protection
#This script will create a send connector that can relay through exchange online protection in Office 365
#Must be run from the on prem Exchange Management Shell
#WARNING: This will use the wildcard * for sending, so please consider changing "addressSpaces" to some testing domains, so you know this works before routing everything.
#WARNING: You must remove your existing internet send connector if you wish for this to work with 100% of all email.
#Author: @michael_mardahl (github.com/mardahl)
#License: MIT - please keep author credits.
$hybridConnector = Get-SendConnector *365*
$smartHost = Resolve-DnsName $hybridConnector.AddressSpaces.Address -Type MX
@mardahl
mardahl / gist:b2a3b0f74e6fd73ab0878085ed1ecc70
Created July 25, 2020 14:41
Function to verify that a certificate by specific template exists, using powershell
function VerifyCertificateExists($issuer, $templateName){
#function that validates existence of required certificate.
#input issuer and template name (wildcards will automatically be added).
#example : VerifyCertificateExists -issuer "myCompany" -templateName "myCertTemplate"
#MIT license - github.com/mardahl
try {
Write-Verbose "Verifying existence of required certificate..." -Verbose
$certs = Get-ChildItem -Path cert:\currentuser\my | Where-Object Issuer -like "*$issuer*" -ErrorAction Stop
$cert = $certs | Where-Object{ $_.Extensions | Where-Object{ ($_.Oid.Value -eq '1.3.6.1.4.1.311.21.7') -and ($_.Format(0) -like "*$templateName*") }} -ErrorAction Stop
if(!$cert){throw}
@mardahl
mardahl / ExternalUserAndGuestSharing.ps1
Last active May 5, 2020 12:57
Enable anyone links on Teams and Office365 groups
# As a default, sharing links with anyone is disabled on Office 365 groupSites, which in turn also means Microsoft Teams Sites.
# Even if you have Anyone sharing enabled at the tenant level!
# This script can help y remove that requirement from a specific site.
# MIT licensing, keep author credits if reusing
# Author: Michael Mardahl @michael_mardahl on twitter
# https://github.com/mardahl
Install-Module -Name Microsoft.Online.SharePoint.PowerShell
ipmo Microsoft.Online.SharePoint.PowerShell