Azure¶
Invoke-OldFilePurge.ps1¶
Synopsis: Removes files older than a specified number of days from a target directory.
Cleans up old files from a given path. Designed for high-volume deletion of small files (e.g. Tomcat temp, IIS logs). Supports recursive scan, logging, and progress reporting.
Parameters:
| Parameter | Description |
|---|---|
Path |
Mandatory. Target directory to clean up. |
DaysOld |
Files older than this many days will be deleted. Default: 7. |
Recurse |
If specified, subdirectories are also scanned. Default: enabled. |
LogDir |
Directory for log output. Created if it does not exist. Default: C:\Temp. |
LogEnabled |
Enable or disable logging. Default: $true. |
Examples:
.\Invoke-OldFilePurge.ps1 -Path "C:\Program Files\Apache Software Foundation\Tomcat 9.0\temp"
.\Invoke-OldFilePurge.ps1 -Path "D:\IIS\Logs" -DaysOld 30 -LogDir "D:\Logs"
Notes
Author: Petr Štěpán Created: 2026-07-02 Version: 1.0.1 Requires: PowerShell 5.1+ Changelog: 1.0.1 - Enforced minimum PowerShell version, enabled strict mode and stop-on-error, fixed $AllFiles.Count being unreliable on Windows PowerShell 5.1 when 0 or 1 file matched. 1.0.0 - Initial version
Remove-OldDiskSnapshot.ps1¶
Synopsis: Finds and removes Azure managed disk snapshots older than a specified number of days.
Connects to the current Azure context (via Az.Compute), enumerates managed disk snapshots - either across one or more given subscriptions, or across every subscription the signed-in account can see, optionally scoped to a single resource group - and deletes any snapshot whose TimeCreated is older than the given threshold. Each deletion is gated behind -WhatIf/-Confirm via ShouldProcess. A single snapshot (or subscription) failing does not stop the run; it is logged and the script continues with the rest.
Parameters:
| Parameter | Description |
|---|---|
DaysOld |
Snapshots with a TimeCreated older than this many days are deleted. Default: 30. |
ResourceGroupName |
Optional. Limits the scan to snapshots in this resource group. If omitted, all snapshots in each processed subscription are scanned. |
SubscriptionId |
Optional. One or more Azure subscription IDs to operate against. If omitted, every subscription visible to the current Az account (Get-AzSubscription) is processed. |
LogDir |
Directory for log output. Created if it does not exist. Defaults to the directory this script lives in ($PSScriptRoot), so logs land next to the script regardless of the caller's current working directory. |
LogEnabled |
Enable or disable file logging. Default: $true. |
Examples:
PS> .\Remove-OldDiskSnapshot.ps1 -DaysOld 60 -WhatIf
Shows which snapshots older than 60 days would be deleted across all visible
subscriptions, without deleting them.
PS> .\Remove-OldDiskSnapshot.ps1 -DaysOld 30 -ResourceGroupName 'rg-vm-prod'
Deletes snapshots older than 30 days in the 'rg-vm-prod' resource group, in every
visible subscription that contains it.
PS> .\Remove-OldDiskSnapshot.ps1 -DaysOld 30 -SubscriptionId '00000000-0000-0000-0000-000000000000','11111111-1111-1111-1111-111111111111'
Deletes snapshots older than 30 days across the two specified subscriptions.
PS> .\Remove-OldDiskSnapshot.ps1 -DaysOld 90 -Confirm:$false
Use -Confirm:$false to run unattended and skip all prompts.
Notes
Author: Petr Stepan Created: 2026-08-10 Version: 1.3.0 Requires: Az.Accounts, Az.Compute modules; an active Connect-AzAccount session. Changelog: 1.3.0 - Default LogDir moved from the OS temp directory to the script's own directory ($PSScriptRoot), so logs are easy to find regardless of the caller's working directory. 1.2.0 - Key progress (current subscription, per-snapshot name/resource group/age, deletion results, summary) is now printed to the console by default, without requiring -Verbose. Per-snapshot deletion prompt now also shows the snapshot's age in days. Interactive per-snapshot confirmation was already provided by ShouldProcess/ConfirmImpact='High' and needs no -Confirm:$false override to opt out of; documented for clarity. 1.1.0 - SubscriptionId is now an array (defaults to all visible subscriptions when omitted); fixed -WhatIf leaking into log-file writes via $WhatIfPreference inheritance on New-Item/Out-File. 1.0.0 - Initial version
Set-AzureSQLPermissions.ps1¶
Synopsis: Grants Azure SQL Database permissions to managed identities listed in a CSV file.
Reads a CSV of ServerName/DatabaseName/ManagedIdentityName/DataReader/DataWriter/Execute rows, authenticates to Azure SQL using an access token from 'az account get-access-token', creates each managed identity as an external database user if it does not already exist, and grants the requested db_datareader/db_datawriter/EXECUTE permissions idempotently. Requires the Azure CLI ('az') and the SqlServer module (Invoke-Sqlcmd) to be installed, and an active 'az login' session with rights to request database access tokens.
Parameters:
| Parameter | Description |
|---|---|
CsvPath |
Path to the input CSV file. Defaults to 'AzureSQLPermissions.csv' next to this script. |
Examples:
PS> .\Set-AzureSQLPermissions.ps1
Processes AzureSQLPermissions.csv from the script folder and applies the permissions.
PS> .\Set-AzureSQLPermissions.ps1 -CsvPath C:\data\perms.csv -WhatIf
Shows which grants would be applied without changing any database.
Notes
Author: Michal Horák Created: 2026-07-21 Version: 1.1.0 Changelog: 1.1.0 - Added standard header, ShouldProcess/-WhatIf support, CsvPath parameter, Set-StrictMode/$ErrorActionPreference, function help blocks, exit 0 on success. 1.0.0 - Initial version