Skip to content

Instantly share code, notes, and snippets.

View RylandDeGregory's full-sized avatar
🎯
Focusing

Ryland RylandDeGregory

🎯
Focusing
View GitHub Profile
@RylandDeGregory
RylandDeGregory / azure-pipelines.yml
Last active May 7, 2020 22:55
Hugo on Azure Storage CI/CD with Azure Pipelines
# CI/CD Pipeline for building & deploying a Hugo static website to Azure Blob Storage.
# Uses Microsoft Azure Hosted agents.
# AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_KEY must be defined as secret pipeline variables.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
@RylandDeGregory
RylandDeGregory / github-actions.yml
Last active December 3, 2020 20:12
Hugo on Azure Storage CI/CD with GitHub Actions
# CI/CD Pipeline for building & deploying a Hugo static website to Azure Blob Storage.
# Uses GitHub Hosted agents.
# AZURE_STORAGE_KEY must be defined as a GitHub repository secret.
name: CI/CD
# Trigger the workflow on push or pull request events, but only for the master branch
on:
push:
branches: [ master ]
pull_request:
@RylandDeGregory
RylandDeGregory / Rename-AzVM.ps1
Last active May 11, 2021 01:20
Rename an Azure Virtual Machine resource
<#
.SYNOPSIS
Rename Azure Virtual Machine(s).
.DESCRIPTION
Rename an Azure Virtual Machine by disconnecting dependent resources, creating new Virtual Machine resource object, and reattaching all dependent resources.
.EXAMPLE
./Rename-AzVM.ps1 -ComputerName 'MyAzureVM1', 'MyAzureVM2' -NewName 'myazvm01', 'AZVM02' -Linux
.EXAMPLE
./Rename-AzVM.ps1 -ComputerName 'AnotherAzureVM' -NewName 'MySuperSpecialAzVM' -Windows
.NOTES
@RylandDeGregory
RylandDeGregory / awx_powershell.dockerfile
Last active January 23, 2021 23:39
Ansible AWX with PowerShell 7
# Build from official ansible/awx image
# Use latest tag unless a different tag is supplied at runtime
ARG AWX_VER=latest
FROM ansible/awx:${AWX_VER}
USER root
# Install PowerShell and NTLM auth package
RUN dnf -y install gssntlmssp \
https://github.com/PowerShell/PowerShell/releases/download/v7.0.3/powershell-lts-7.0.3-1.rhel.7.x86_64.rpm
@RylandDeGregory
RylandDeGregory / Get-EC2SnapshotParentMapping.ps1
Last active February 3, 2021 00:31
Correlate EC2 Snapshots with the EBS Volume and/or EC2 Instance each was created from.
<#
.SYNOPSIS
Map all EC2 Snapshots in an AWS Account to the EBS Volume that is was created from, and map that EBS Volume to an EC2 Instance if it's attached to one.
.EXAMPLE
.\Get-EC2SnapshotParentMapping.ps1 -Account '123456789012' -Regions 'us-east-1', 'us-west-2' -AccessKey '<AWS Access Key>' -SecretKey '<AWS Secret Key>' -UseRoleAssumption
.EXAMPLE
.\Get-EC2SnapshotParentMapping.ps1 -Account '123456789012' -Regions 'us-east-1' -AccessKey '<AWS Access Key>' -SecretKey '<AWS Secret Key> -SessionToken '<AWS STS Token>'
.OUTPUTS
A .csv file containing the generated Snapshot correlation matrix, located on the script executor's Desktop.
#>
@RylandDeGregory
RylandDeGregory / Start-SpotifyPlaylistExport.ps1
Created February 22, 2021 14:07
Export Spotify playlists to .csv file using PowerShell. Uses Spotify web API with OAuth2 Client Authorization flow
<#
.SYNOPSIS
Export Spotify playlists to .csv file for backup
.DESCRIPTION
Export Spotify playlists to .csv file using the Spotify web API with OAuth2 Client Authorization flow
.EXAMPLE
./Start-SpotifyPlaylistExport.ps1 -KeyVaultName 'myazkeyvault' -PlaylistType 'User'
.NOTES
- Assumes that a Spotify application has been configured and an OAuth2 Refresh token has been granted for a user
https://developer.spotify.com/documentation/general/guides/authorization-guide/
@RylandDeGregory
RylandDeGregory / Uninstall-OldAzModules.ps1
Last active May 18, 2022 18:00
Remove all but the latest version of Azure PowerShell modules. Run after executing "Update-Module -Name Az*"
function Uninstall-OldModules {
param(
# Array of modules to uninstall
[Parameter(Mandatory)]
$Modules
)
foreach ($Module in $Modules) {
if ($Module.Count -gt 1) {
$LatestVersion = $Module.Group | Sort-Object Version | Select-Object Version -Last 1
Write-Output "Removing all versions of $($Module.Name) except latest installed: $($LatestVersion.Version)"
@RylandDeGregory
RylandDeGregory / PSAppInsights.ps1
Last active November 20, 2023 23:23
PowerShell and AppInsights sample code and binary library
## Requires Microsoft.ApplicationInsights.dll from: https://www.nuget.org/packages/Microsoft.ApplicationInsights/ ##
## Unzip the .nupkg file and extact the "lib/net452/Microsoft.ApplicationInsights.dll" ##
## Upload the .dll to the same directory as "run.ps1" within the Function App
# Load .dll assembly into PowerShell session
[Reflection.Assembly]::LoadFile("$PSScriptRoot\Microsoft.ApplicationInsights.dll")
# Instantiate the Telemetry Client configuration
$TelemetryClientConfig = [Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration]::CreateDefault()
@RylandDeGregory
RylandDeGregory / Get-CloudOrphanedVolumes.ps1
Created June 6, 2021 18:01
Generate a CSV report of all Azure and AWS disks (volumes) that are not attached to a virtual machine
#Requires -Version 6.0
#Requires -Modules Az.Accounts, Az.ResourceGraph, AWS.Tools.Common, AWS.Tools.SecurityToken, AWS.Tools.EC2
<#
.SYNOPSIS
Generate a report of cloud (Azure & AWS) orphaned volumes
.DESCRIPTION
Generate a report of Azure Disks and AWS EBS Volumes which are not attached to any virtual machine
.EXAMPLE
Process all Azure Subscriptions, multiple AWS Accounts, and multiple AWS Regions
.\Get-CloudOrphanedVolumes.ps1 -AccessKey 'AKWAVDLECACDWDL' -SecretKey 'Acs320xcew2ds2SLdwsf0' -AWSAccount '12345679012', '123049238343' -AWSRegion 'us-east-1', 'us-west-2'
@RylandDeGregory
RylandDeGregory / Get-AzOrphanedVolumes.ps1
Created June 6, 2021 21:47
Generate a report of all Azure and AWS disks (volumes) that are not attached to a virtual machine. Output to stdout or to CSV file.
#Requires -Version 6.0
#Requires -Modules Az.Accounts, Az.ResourceGraph
<#
.SYNOPSIS
Generate a report of Azure orphaned volumes
.DESCRIPTION
Generate a report of Azure Disks which are not attached to any virtual machine
.EXAMPLE
Process all Azure Subscriptions and write results to stdout
.\Get-AzOrphanedVolumes.ps1