This directory contains PowerShell scripts that automate Azure operations using the Az PowerShell modules. Scripts include both organized subfolder scripts and standalone automation scripts for common Azure tasks.
- PowerShell 5.1+: Windows PowerShell or PowerShell Core
- Az PowerShell Modules: Automatically installed by scripts when needed
- Azure Subscription: Valid Azure subscription with appropriate permissions
Scripts authenticate using Azure PowerShell authentication:
# Interactive login
Connect-AzAccount
# Service principal login
$credential = Get-Credential
Connect-AzAccount -ServicePrincipal -Credential $credential -Tenant "tenant-id"
# Managed identity (when running on Azure resources)
Connect-AzAccount -Identity| Folder | Description | Service Focus |
|---|---|---|
avd/ |
Azure Virtual Desktop | AVD host pools, session hosts, scaling |
| Script | Description | Use Case |
|---|---|---|
az-ps-create-linux-vm.ps1 |
Linux VM creation | Deploy Ubuntu/CentOS VMs |
az-ps-start-vm.ps1 |
Start an Azure VM | Power on deallocated VMs |
az-ps-stop-vm.ps1 |
Stop and deallocate a VM | Cost management, maintenance |
az-ps-create-vm-snapshot.ps1 |
OS disk snapshot | Pre-change backup of VM OS disk |
az-ps-enable-backup.ps1 |
Enable Azure Backup | Protect VMs with Recovery Services vault |
az-ps-create-vm-scale-set.ps1 |
VM Scale Set deployment | Auto-scaling VM groups |
az-ps-delete-running-vms.ps1 |
Bulk VM cleanup | Cost management, testing cleanup |
az-ps-image-builder-windows-cleanup.ps1 |
Image Builder cleanup | Remove temporary resources |
az-ps-install-nginx-linux-vm.ps1 |
NGINX web server setup | Web server automation |
az-ps-install-webserver-windows.ps1 |
IIS web server setup | Windows web server deployment |
Create-NewWindowsVm.ps1 |
Windows VM creation | Standard Windows VM deployment |
| Script | Description | Status |
|---|---|---|
wip_az-ps-create-image-avd.ps1 |
AVD image creation | Development |
wip_az-ps-image-builder-windows.ps1 |
Windows image building | Development |
Scripts automatically install required Az modules:
function Test-AzModule {
param($ModuleName)
if (-not (Get-Module -Name $ModuleName -ListAvailable)) {
Write-Host "Installing $ModuleName..." -ForegroundColor Yellow
Install-Module -Name $ModuleName -Force -AllowClobber -Scope CurrentUser
}
Import-Module $ModuleName -Force
}All scripts use comprehensive validation:
[ValidateSet("East US", "West US 2", "West Europe")]
[string]$Location
[ValidatePattern('^[a-zA-Z0-9-]{3,24}$')]
[string]$ResourceGroupName
[ValidateSet("Standard_B2s", "Standard_D2s_v3", "Standard_F2s_v2")]
[string]$VMSizeScripts implement robust error handling:
$ErrorActionPreference = 'Stop'
try {
$vm = New-AzVM -ResourceGroupName $ResourceGroupName `
-Name $VMName `
-Location $Location `
-Size $VMSize
}
catch {
Write-Error "VM creation failed: $($_.Exception.Message)"
# Cleanup partial resources
exit 1
}.\az-ps-create-linux-vm.ps1 `
-VMName "MyLinuxVM" `
-ResourceGroupName "MyRG" `
-Location "East US" `
-AdminUsername "azureuser".\Create-NewWindowsVm.ps1 `
-VMName "MyWindowsVM" `
-ResourceGroupName "MyRG" `
-Location "East US" `
-AdminUsername "azureadmin".\az-ps-create-vm-scale-set.ps1 `
-ScaleSetName "MyVMSS" `
-ResourceGroupName "MyRG" `
-Location "East US" `
-InstanceCount 3# Install NGINX on Linux VM
.\az-ps-install-nginx-linux-vm.ps1 `
-VMName "MyLinuxVM" `
-ResourceGroupName "MyRG"
# Install IIS on Windows VM
.\az-ps-install-webserver-windows.ps1 `
-VMName "MyWindowsVM" `
-ResourceGroupName "MyRG"# Delete all running VMs in resource group
.\az-ps-delete-running-vms.ps1 `
-ResourceGroupName "MyRG" `
-Force- Credential Management: Use Azure PowerShell credential management
- RBAC: Ensure minimal required permissions for operations
- Resource Tagging: All resources are tagged for governance
- Secure Connections: Scripts use secure communication protocols
- Module Management: Scripts handle Az module installation automatically
- Resource Organization: Use consistent resource group strategies
- Naming Conventions: Follow Azure naming best practices
- Cost Management: Include cleanup scripts and resource monitoring
- Documentation: Each script includes detailed help and examples
-
Module Not Found
Module 'Az.Compute' not found- Solution: Scripts auto-install modules or run
Install-Module Az.Compute
- Solution: Scripts auto-install modules or run
-
Not Authenticated
Run Connect-AzAccount to login- Solution: Run
Connect-AzAccountto authenticate
- Solution: Run
-
Subscription Not Set
No subscription found- Solution: Set subscription with
Set-AzContext -SubscriptionId <id>
- Solution: Set subscription with
-
Resource Name Conflict
Resource name already exists- Solution: Use unique names or check existing resources
-
Quota Exceeded
Quota exceeded for resource type- Solution: Check quotas and request increases if needed
Most scripts support these standard parameters:
Location: Azure region for resource deploymentResourceGroupName: Target resource group (created if doesn't exist)SubscriptionId: Specific subscription to useForce: Skip confirmation promptsWhatIf: Preview operations without executingTags: Resource tags as hashtable
- Automatic resource group creation
- Consistent resource naming and tagging
- Cleanup procedures for failed deployments
- Resource dependency management
- Custom script extensions for post-deployment configuration
- Network security group creation and configuration
- Public IP and DNS name assignment
- Disk encryption and backup configuration
- Progress reporting with colored output
- Detailed logging of operations
- Performance metrics and timing
- Parallel processing where applicable
Common Az modules used:
Az.Accounts: Authentication and subscription managementAz.Compute: Virtual machines and scale setsAz.Network: Virtual networks and security groupsAz.Storage: Storage accounts and disk managementAz.Resources: Resource groups and deploymentsAz.KeyVault: Key and secret management
When adding new scripts:
- Follow the established parameter validation patterns
- Include automatic module installation
- Add comprehensive error handling with cleanup
- Include detailed help documentation with examples
- Test with multiple Azure regions and scenarios
- Update this README with new script descriptions
- Use parallel processing for bulk operations
- Implement progress reporting for long-running tasks
- Include timeout handling for network operations
- Optimize resource creation order for dependencies
For issues or questions:
- Check the individual script help documentation
- Review Azure PowerShell documentation
- Consult Azure service-specific PowerShell cmdlet reference
- Verify Azure credentials and permissions