Skip to content

Instantly share code, notes, and snippets.

View blakedrumm's full-sized avatar
🏠
Working from home

Blake Drumm blakedrumm

🏠
Working from home
View GitHub Profile
@blakedrumm
blakedrumm / Remove-UpdateManagerOldStatusFiles.ps1
Created June 13, 2025 14:44
PowerShell script to remove WindowsPatchExtension status files with indexes higher than the latest settings file, for Update Manager cleanup.
<#
.SYNOPSIS
Removes status files with indexes greater than the highest index found in the settings directory.
.DESCRIPTION
This script automatically finds the latest versioned extension directory for the WindowsPatchExtension,
identifies the highest-numbered `.settings` file under the `RuntimeSettings` directory, and deletes all
`.status` files under the corresponding `status` directory that have a higher numeric index.
.PARAMETER None
@blakedrumm
blakedrumm / AzureArcVersions.kql
Created May 19, 2025 21:13
Retrieves Azure Arc-enabled machines with their agent version, OS version, status, cloud provider, and last status change timestamp (in UTC). Helps identify machines with outdated Arc agents or stale status updates.
resources
| where type == "microsoft.hybridcompute/machines"
| extend
ArcAgentVersion = tostring(properties.agentVersion),
OSVersion = tostring(properties.osSku),
MachineName = tostring(properties.machineFqdn),
Status = tostring(properties.status),
LastStatusChangeRaw = todatetime(properties.lastStatusChange),
LastStatusChangeUTC = format_datetime(todatetime(properties.lastStatusChange), 'yyyy-MM-dd HH:mm:ss'),
Provider = tostring(properties['cloudMetadata']['provider'])
@blakedrumm
blakedrumm / Set-AzureRoleAssignments.ps1
Last active May 13, 2025 15:40
PowerShell script to automate Azure role assignments for a specified user or managed identity across multiple subscriptions. Reads subscription data from a JSON file, verifies role existence, prevents duplicate assignments, and provides clear processing output. Useful for managing RBAC at scale in Azure environments.
<#
.SYNOPSIS
Assigns specified Azure roles to a user or managed identity across multiple subscriptions.
.DESCRIPTION
This script reads subscription IDs from a JSON file and assigns predefined roles at the subscription scope
to a specified principal (user or managed identity). It handles Azure authentication, validates role existence,
checks for existing assignments to avoid duplication, and outputs clear processing results.
The script is designed for environments requiring consistent role assignments across multiple Azure subscriptions.
@blakedrumm
blakedrumm / Start-OnDemandVmBackup.ps1
Last active May 1, 2025 18:55
This PowerShell script is designed for use in Azure Automation to initiate an on-demand backup of one or more Azure VMs protected by a Recovery Services Vault. It authenticates using a system-assigned managed identity, locates the associated vault and backup container for each VM, and triggers the backup. Output is timestamped and includes detai…
<#
.SYNOPSIS
Triggers an on-demand backup for one or more Azure VMs using Recovery Services Vault.
.DESCRIPTION
This script connects to Azure using a system-assigned managed identity (MSI) and loops through one or more VMs
to identify their registered backup container and trigger an on-demand backup job. It provides formatted and
timestamped console output and handles common errors such as concurrent backup operations.
.PARAMETER SubscriptionId
@blakedrumm
blakedrumm / Migrate-AzureAutomationAccounts.ps1
Last active May 1, 2025 18:47
This PowerShell script is designed to migrate runbooks, variables, schedules, modules, certificates, connections, credentials, webhooks, private endpoints, and their tags across tenants. All PS 5 and PS 7 runbooks will be imported as PS 5 runtime; you can change it via the runtime environment later.
<#
.SYNOPSIS
This PowerShell script migrates runbooks, variables, schedules, modules, certificates, connections, credentials, webhooks, private endpoints, and their tags across tenants.
.DESCRIPTION
This PowerShell script is designed to migrate runbooks, variables, schedules, modules, certificates, connections, credentials, webhooks, private endpoints, and their tags across tenants. All PS 5 and PS 7 runbooks will be imported as PS 5 runtime; you can change it via the runtime environment later.
.PARAMETER oldSubscriptionId
Required. Source subscription of the Azure Automation account.
@blakedrumm
blakedrumm / Get-PythonModuleDependencies.ps1
Last active November 13, 2024 03:37
Fetch and display PyPI dependencies for a specified Python module and version in a formatted table.
<#
.SYNOPSIS
This script retrieves dependency information for specified Python modules and versions from PyPI.
.DESCRIPTION
The `Get-PythonModuleDependencies` function fetches dependency details for multiple specified Python modules and versions by accessing the PyPI JSON metadata. The dependencies, if any, are displayed in a structured table format, showing the module name, operator, version, and any conditions. Additionally, the script outputs information about each main module and version being checked, along with URLs for the PyPI project and JSON metadata.
.PARAMETER ModuleNames
An array of Python module names to check for dependencies.
@blakedrumm
blakedrumm / Write-Console.ps1
Last active October 16, 2024 01:47
Enhance your PowerShell scripts with Write-Console for displaying messages with optional timestamps and customizable colors. Utilize dynamic rainbow mode to create colorful, segmented outputs where each character has a unique color, ensuring no consecutive duplicates. Improve readability and organization in your console applications effortlessly…
<#
.SYNOPSIS
Provides advanced console output functionality with customizable timestamps and colorization options.
.DESCRIPTION
This script contains the `Write-Console` function to enhance PowerShell console output.
It offers features such as customizable timestamps, colored text, and segmented messages with advanced formatting.
A "Rainbow" mode is included, which applies unique colors to each character, improving readability and visual organization.
.EXAMPLE
@blakedrumm
blakedrumm / Convert-NonEncryptedAutomationVariables.ps1
Last active November 20, 2024 08:17
PowerShell script to convert non-encrypted variables in an Azure Automation Account to encrypted variables. This script retrieves all variables in the Automation Account, checks if they are encrypted, and converts non-encrypted variables by re-creating them with encryption enabled.
<#
.SYNOPSIS
This script converts non-encrypted Automation Account variables to encrypted ones.
.DESCRIPTION
The script retrieves all variables from an Azure Automation Account and checks if they are encrypted. If any variables are not encrypted, it removes and re-creates the variable with encryption enabled. It outputs the status of each variable during the process.
.PARAMETER ResourceGroupName
The name of the Azure Resource Group containing the Automation Account.
@blakedrumm
blakedrumm / Get-AzureQuotaUsage.ps1
Created August 28, 2024 15:10
PowerShell script to gather Azure quota and usage data across various services, allowing for region and subscription customization.
<#
.SYNOPSIS
This script gathers Azure quota and usage data for various services like Virtual Machines, Managed Disks, Storage, Networking, etc., for a specified region and outputs the data.
Optionally, it exports the data to a CSV file.
.DESCRIPTION
The script connects to your Azure subscription and retrieves usage and quota information for multiple services such as Virtual Machines, Managed Disks, Storage, and Networking.
It sorts the data by usage percentage and displays it in a formatted table. If needed, the data can also be exported to a CSV file.
.PARAMETER Location
@blakedrumm
blakedrumm / Invoke-AzMaintenance.ps1
Last active August 15, 2024 16:04
PowerShell script to manage Azure VMs during maintenance events. The script processes webhook data to determine the maintenance event type and manages Azure VMs accordingly by stopping services in 'pre' mode and starting them in 'post' mode.
<#
.SYNOPSIS
This script manages Azure VMs during maintenance events by stopping and starting services based on the specified mode.
.DESCRIPTION
The script processes webhook data to determine the maintenance event type and manages Azure VMs accordingly. It stops services in 'pre' mode and starts them in 'post' mode.
.PARAMETER ScriptMode
Specifies the mode of the script. Valid values are 'Pre' and 'Post'.