-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rename-Azure-Subscriptions-with-Azure-CLI-and-PowerShell.ps1
103 lines (69 loc) · 5.43 KB
/
Rename-Azure-Subscriptions-with-Azure-CLI-and-PowerShell.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<#
.SYNOPSIS
A script used to rename Azure Subscriptions with Azure CLI and PowerShell.
.DESCRIPTION
A script used to rename Azure Subscriptions with the use of Azure CLI and Azure PowerShell.
.NOTES
Filename: Rename-Azure-Subscriptions-with-Azure-CLI-and-PowerShell.ps1
Created: 21/02/2022
Last modified: 21/02/2022
Author: Wim Matthyssen
Action: Change variables were needed to fit your needs.
Disclaimer: This script is provided "As IS" with no warranties.
.EXAMPLE
.\Rename-Azure-Subscriptions-with-Azure-CLI-and-PowerShell.ps1
.LINK
https://wmatthyssen.com/2021/04/21/azure-governance-rename-an-azure-subscription-with-azure-cli-and-powershell/
#>
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Sign in with Azure CLI (CLI)
az login
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Update Azure CLI to the latest version (CLI)
az upgrade
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Variables
$companyShortName = "<companyShortName>" # <your company short name here> Best is to use a three letter abbreviation. Example: "myh"
$productionShortName = "<production short name here>" # Best is to use a three letter abbreviation. Example: "prd"
$acceptanceShortName = "<acceptance short name here>" # Best is to use a three letter abbreviation. Example: "acc"
$developmentShortName = "<development short name here>" # Best is to use a three letter abbreviation. Example: "dev"
$testShortName = "<test short name here>" # Best is to use a three letter abbreviation. Example: "tst"
$subIdManagement = "<your Management Subcriprition ID here>" # Example: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$subIdIdentity = "<your Identity Subcriprition ID here>" # Example: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$subIdConnectivity = "<your Connectivity Subcriprition ID here>" # Example: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$subIdProduction = "<your Production Subcriprition ID here>" # Example: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$subIdAcceptance = "<your Acceptance Subcriprition ID here>" # Example: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$subIdDevelopment = "<your Development Subcriprition ID here>" # Example: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$subIdTest = "<your Test Subcriprition ID here>" # Example: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
$subNameManagement = "sub-management-" + $companyShortName + "-01"
$subNameIdentity = "sub-identity-" + $companyShortName + "-01"
$subNameConnectivity = "sub-connectivity-" + $companyShortName + "-01"
$subNameProduction = "sub-" + $productionShortName + "-" + $companyShortName + "-01"
$subNameAcceptance = "sub-" + $acceptanceShortName + "-" + $companyShortName + "-01"
$subNameDevelopment = "sub-" + $developmentShortName + "-" + $companyShortName + "-01"
$subNameTest = "sub-" + $testShortName + "-" + $companyShortName + "-01"
$global:currenttime= Set-PSBreakpoint -Variable currenttime -Mode Read -Action {$global:currenttime= Get-Date -UFormat "%A %m/%d/%Y %R"}
$foregroundColor1 = "Red"
$foregroundColor2 = "Yellow"
$writeEmptyLine = "`n"
$writeSeperatorSpaces = " - "
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Start script execution
Write-Host ($writeEmptyLine + "# Script started. Without any errors, it will need around 6 minutes to complete" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor1 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Rename subscriptions (CLI)
az account subscription rename --subscription-id $subIdManagement --name $subNameManagement
az account subscription rename --subscription-id $subIdIdentity --name $subNameIdentity
az account subscription rename --subscription-id $subIdConnectivity --name $subNameConnectivity
az account subscription rename --subscription-id $subIdProduction --name $subNameProduction
az account subscription rename --subscription-id $subIdAcceptance --name $subNameAcceptance
az account subscription rename --subscription-id $subIdDevelopment --name $subNameDevelopment
az account subscription rename --subscription-id $subIdTest --name $subNameTest
Write-Host ($writeEmptyLine + "# All subscriptions are renamed" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Write script completed
Write-Host ($writeEmptyLine + "# Script completed" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor1 $writeEmptyLine
## ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------