-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGet-all-Azure-classic-subscription-administrators.ps1
103 lines (71 loc) · 4.76 KB
/
Get-all-Azure-classic-subscription-administrators.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 find all Azure classic subscription administrators from all Azure Subscriptions in an Azure tenant.
.DESCRIPTION
A script used to find all Azure classic subscription administrators from all Azure Subscriptions in an Azure tenant.
The script will do all of the following:
Remove the breaking change warning messages.
Get all Azure subscriptions and store them in a variable.
Get and list all Azure classic subscription administrators for each subscription.
.NOTES
Filename: Get-all-Azure-classic-subscription-administrators.ps1
Created: 20/03/2024
Last modified: 20/03/2024
Author: Wim Matthyssen
Version: 1.0
PowerShell: Azure PowerShell and Azure Cloud Shell
Requires: PowerShell Az (v10.4.1)
Action: Change variables were needed to fit your needs.
Disclaimer: This script is provided "as is" with no warranties.
.EXAMPLE
Connect-AzAccount
Get-AzTenant (if not using the default tenant)
Set-AzContext -tenantID "xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx" (if not using the default tenant)
.\Get-all-Azure-classic-subscription-administrators.ps1
.LINK
https://wmatthyssen.com/2024/03/21/list-azure-classic-subscription-administrators-via-the-azure-portal-or-via-an-azure-powershell-script/
#>
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Variables
# Time, colors, and formatting
Set-PSBreakpoint -Variable currenttime -Mode Read -Action {$global:currenttime = Get-Date -Format "dddd MM/dd/yyyy HH:mm"} | Out-Null
$foregroundColor1 = "Green"
$foregroundColor2 = "Yellow"
$writeEmptyLine = "`n"
$writeSeperatorSpaces = " - "
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Remove the breaking change warning messages
Set-Item -Path Env:\SuppressAzurePowerShellBreakingChangeWarnings -Value $true | Out-Null
Update-AzConfig -DisplayBreakingChangeWarning $false | Out-Null
$warningPreference = "SilentlyContinue"
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Write script started
Write-Host ($writeEmptyLine + "# Script started. Without errors, it takes up to 1 minute to complete" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor1 $writeEmptyLine
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Get all Azure subscriptions and store them in a variable
$subscriptions = Get-AzSubscription
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Get and list all Azure classic subscription administrators for each subscription
foreach ($sub in $subscriptions) {
Set-AzContext -SubscriptionId $sub.Id | Out-Null
$classicAdmins = Get-AzRoleAssignment -IncludeClassicAdministrators | Where-Object {$_.RoleDefinitionName -like "*ServiceAdministrator*" -or $_.RoleDefinitionName -like "*CoAdministrator*"}
Write-Output "Subscription: $($sub.Name) - $($sub.Id)"
if ($classicAdmins) {
foreach ($admin in $classicAdmins) {
Write-Host ($writeEmptyLine + "# Classic Administrator: $($admin.SignInName)" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor2 $writeEmptyLine
#Write-Output "Classic Administrator: $($admin.SignInName)" -foregroundcolor $foregroundColor2
}
} else {
Write-Host ($writeEmptyLine + "# No classic administrators found" + $writeSeperatorSpaces + $currentTime)`
$writeEmptyLine
#Write-Output "No classic administrators found."
}
Write-Output ""
}
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
## Write script completed
Write-Host ("# Script completed" + $writeSeperatorSpaces + $currentTime)`
-foregroundcolor $foregroundColor1 $writeEmptyLine
## ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------