Skip to content

Instantly share code, notes, and snippets.

@rupertbenbrook
rupertbenbrook / motd.sh
Created August 8, 2021 16:40
Motd generator - goes in /etc/periodic/15min/motd.sh
#!/bin/sh
UPTIME_DAYS=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 / 86400)
UPTIME_HOURS=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 % 86400 / 3600)
UPTIME_MINUTES=$(expr `cat /proc/uptime | cut -d '.' -f1` % 31556926 % 86400 % 3600 / 60)
cat > /etc/motd << EOF
____ _ _
| _ \ | | | |
| |_) | ___ _ __ | |__ _ __ ___ ___ | | __
@rupertbenbrook
rupertbenbrook / CreateHighDensityAppService.ps1
Last active August 4, 2020 09:14
Azure App Service High Density Scaling Tests based on https://docs.microsoft.com/en-us/azure/app-service/manage-scale-per-app. Tested running on PowerShell Core 7 with Az Cmdlets and .NET 3.1 SDK.
param (
[string] $ResourceGroup = "rbtesthighdensity",
[string] $Location = "northeurope",
[string] $AppPrefix = "rbaathd",
[int] $PlanScale = 4,
[int] $AppCount = 8,
[int] $WorkerScale = 1,
[bool] $FirstAppLarge = $true
)
@rupertbenbrook
rupertbenbrook / Configure-OpenSSHD.ps1
Created August 10, 2019 09:23
Configure Windows Server 2019+ for SSHD with PowerShell
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
@rupertbenbrook
rupertbenbrook / alpine-setup.sh
Last active November 9, 2023 14:03
Alpine with Docker on Hyper-V Initial Setup
#!/bin/sh
# Initial set up script for Alpine as a Docker host in a Hyper-V VM
# Based on https://wiki.alpinelinux.org/wiki/Docker and https://wiki.alpinelinux.org/wiki/Hyper-V_guest_services
# Tested on Alpine 3.10
# wget -O - https://bit.ly/alpine-docker | sh
# Include community repo and update/upgrade
sed -i '/alpine\/v3.10\/community/s/^#*//g' /etc/apk/repositories
apk update
apk upgrade
@rupertbenbrook
rupertbenbrook / Update-AzureRmNetworkSecurityGroupRuleConfigFromDnsUpdateTags.ps1
Last active February 18, 2022 05:06
Script to update all the Azure Network Security Groups in a subscription that have specific tags on them to indicate the source or destination addresses of the NSG rules need to be updated from DNS lookups. Useful when wanting to set NSGs for specific DNS names as opposed to IP addresses, and can be run on a schedule in an Azure Automation Runbook.
# NSGs need to have the tags UpdateInboundSrcFromDns and/or UpdateOutboundDstFromDns set
# Tag values follow the pattern <ruleNamePrefix>:<dnsName>,<ruleNamePrefix>:<dnsName>,etc.
# <ruleNamePrefix> is the name of the rule to be updated
# <dnsName> is the DNS name to lookup the addresses for
# Using the tag UpdateInboundSrcFromDns updates the SourceAddressPrefix of the matching rule to the addresses for the DNS lookup
# Using the tag UpdateOutboundDstFromDns updates the DestinationAddressPrefix of the matching rule to the addresses for the DNS lookup
# A single DNS name can resolve to one or more addresses, so a rule will be created for each address
# Each rule created will increase the priority of the original rule by one for each address, so rules need to be spaced in priority appropriately
# This script can be scheduled in an Azure Automation Runbook to regularly update NSGs from DNS, allowing NSGs to adapt to DNS changes
# If this is done, the schedule for the script should be something less than the TTL
@rupertbenbrook
rupertbenbrook / CreateOffice365AzureDnsRecords.ps1
Created April 29, 2017 16:47
Creates the basic Office 365 DNS records in an Azure DNS zone
param (
[Parameter(Mandatory=$true)]
$ResourceGroupName,
[Parameter(Mandatory=$true)]
$ZoneName,
$TTL = 3600
)
@rupertbenbrook
rupertbenbrook / chocolatey.txt
Created April 20, 2017 18:36
My default Chocolatey packages for development
7zip.install,git.install,putty.install,nodejs,windowsazurepowershell,azcopy,azurestorageexplorer,paint.net,keepass.install,sysinternals,googlechrome,visualstudiocode,sql-server-management-studio
@rupertbenbrook
rupertbenbrook / policy.xml
Last active May 3, 2021 19:42
Azure API Management inbound policy for backend OAuth2 client credentials flow with token caching
<!--
This relies on a number of properties being defined in API Management:
• EnableCache – Either “true” or “false”. This is used to enable and disable caching of tokens.
• OAuth2TokenEndpoint – The AAD OAuth2 token endpoint URI to get a token from. It takes the form https://login.microsoftonline.com/<subscription-guid>/oauth2/token.
• OAuth2ClientCredentials – The client ID GUID of the AAD application registered for the API Management server to authenticate.
• OAuth2ClientSecret – The client secret key generated for the AAD application registered for the API Management server.
• OAuth2Resource – The application ID URI for the application whose API is being accessed, and who is enabled for delegation in the AAD application registered for the API Management server.
-->
@rupertbenbrook
rupertbenbrook / DownloadUpdates.ps1
Last active May 7, 2017 15:23
Basic initial set up of a Windows VM
#
# To run this script from here, run the following in an admin PowerShell console:
# . { iwr -useb https://gist.githubusercontent.com/rupertbenbrook/ae369cf962b7b3e134aa027d83bff4e3/raw/DownloadUpdates.ps1 } | iex
#
# Download and install any updates, rebooting if needed
Write-Host "Searching for updates..."
$update = New-Object -ComObject "Microsoft.Update.Session"
$updateSearch = $update.CreateUpdateSearcher()
$result = $updateSearch.Search("IsInstalled=0 and Type='Software' and IsHidden=0")
@rupertbenbrook
rupertbenbrook / AzureFilesBackupExample.ps1
Created September 28, 2016 20:17
A demo of using AzCopy to create backups of Azure files shares into blob storage, and restoring them again
#############################################################
# SET UP DEMO STORAGE
#############################################################
# Parameters
$prefix = "rbdemo" # CHANGE THIS!
$rgName = $prefix + "backup"
$location = "northeurope"
$filesStorage = $prefix + "files"
$filesStorageSku = "Standard_LRS" # Use LRS for file share