This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Task 2: Replace Tag Name, keep the original Tag Value: | |
# Get all Az Subscriptions | |
$Subscriptions = Get-AzSubscription | |
#Define old and new tag names | |
$WrongName = "WrongTagName" | |
$CorrectName = "CorrectTagName" | |
#Subscription loop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Task 1: Replace Tag Value, keep Tag Name: | |
# Get all Az Subscriptions | |
$Subscriptions = Get-AzSubscription | |
$TagName = 'YourTagName' | |
$WrongValue = 'wrong tag value' | |
$CorrectValue = 'new tag value' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Create an Azure Automation Account with PowerShell: | |
$automationAccount = @{ | |
Name = "MyAutomationAccount"; | |
ResourceGroupName = "MyResourceGroup"; | |
Location = "westus2"; | |
Tags = @{ | |
"Environment" = "Test"; | |
"Project" = "BlogPost"; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Create new KeyVault with PowerShell | |
$KeyVault = @{ | |
Name = "myKeyVaultName" | |
ResourceGroupName = "myResourceGroupName" | |
Location = "myLocation" | |
EnabledForDeployment = $false | |
EnabledForTemplateDeployment = $false | |
EnabledForDiskEncryption = $false | |
tags = @{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$VMs = @('VM1', 'VM2', 'VM3', 'VM4') | |
$Tag = @{VMPasswordReset = "Yes"} | |
foreach ($VMName in $VMs) { | |
$VM = Get-AzResource -ResourceType "Microsoft.Compute/VirtualMachines" -Name $VMName | |
Update-AzTag -ResourceId $VM.ResourceId -Tag $Tag -Operation Merge | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write-Output "Connecting ..." | |
# Ensures you do not inherit an AzContext in your runbook | |
Disable-AzContextAutosave -Scope Process | |
# Connect to Azure with system-assigned managed identity | |
$AzureContext = (Connect-AzAccount -Identity).context | |
# Set and store context | |
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Azure CLI cmd of the day - January 2022: | |
#1 List existing subscriptions, select one to work with, list default: | |
az account list -o table | |
az account set -s '<Subscription Name>' | |
az account list --query "[?isDefault]" -o table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get variables | |
$tagName = "ExpirationDate" | |
$prodTagValue = "Production" | |
$emailFrom = Get-AutomationVariable -Name "EmailFrom" | |
$emailTo = Get-AutomationVariable -Name "EmailTo" | |
$smtpServer = Get-AutomationVariable -Name "SmtpServer" | |
$logPath = "C:\Temp\AzureResourceGroupDeletion.log" | |
$daysBeforeExpiration = Get-AutomationVariable -Name "DaysBeforeExpiration" | |
# Get all resource groups with the ExpirationDate tag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#PowerShell wrapper script for WinGet | |
#List of apps that will be installed like this: | |
#silently | |
#scope: all users | |
#preferabbly from msstore | |
$apps = @( | |
@{name = "Microsoft.PowerShell"} #MicrosoftPowerShell | |
@{name = "Microsoft.AzureCLI" } #Azure CLI |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace System.Net | |
# Input bindings are passed in via param block. | |
param($Request, $TriggerMetadata) | |
#Get Az Subscription and Set Context | |
$SubscriptionName = "Microsoft Azure Sponsorship" | |
Get-AzSubscription -SubscriptionName $SubscriptionName | Set-AzContext | |
#Get parameter Resource Group Name |
OlderNewer