Skip to main content

PowerShell script with GUI to Query Azure Accounts | User Groups, Applications, Licenses

23 January, 2021
This video highlights how to build a PowerShell script GUI and query Microsoft Azure user groups, applications, and licenses.

PowerShell Script:

<##
    Powershell script with GUI that query Microsoft Azure User Resources, Groups, Applications and Licensing.
    Written by AIP Solutions - hello@aipsolutions.tech 

##>

# Install Azure Module
# Install-Module -Name AzureAD

# Connect to Azure
# Connect-AzureAD

# Disconnect from Azure
# Disconnect-AzureAD

# Use the class System.Windows.Forms
Add-Type -assembly System.Windows.Forms

# Create the screen form (window) to contain elements
$main_form = New-Object System.Windows.Forms.Form

# Set the title and size of the window
$main_form.Text ='Azure AD Account Query - aipsolutions.tech'
$main_form.Width = 600
$main_form.Height = 400

# AutoSize property to make the form automatically stretch
$main_form.AutoSize = $true

# Create a label element on the form
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "Azure Users"
$Label.Location = New-Object System.Drawing.Point(0,10)
$Label.AutoSize = $true
$main_form.Controls.Add($Label)

#Drop Down Box
$ComboBox = New-Object System.Windows.Forms.ComboBox
$ComboBox.Width = 300

# Get Users
$Users = (Get-AzureADUser -All $true).DisplayName

#Add users to Drop Down Box
Foreach ($User in $Users){
    $ComboBox.Items.Add($User)
}

$ComboBox.Location = New-Object System.Drawing.Point(80,10)
$main_form.Controls.Add($ComboBox)

#Create Labels for Forms
$Label2 = New-Object System.Windows.Forms.Label
$Label2.Text = "User Groups:"
$Label2.Location = New-Object System.Drawing.Point(0,40)
$Label2.AutoSize = $true
$main_form.Controls.Add($Label2)

$Label3 = New-Object System.Windows.Forms.Label
$Label3.Text = ""
$Label3.Location = New-Object System.Drawing.Point(110,40)
$Label3.AutoSize = $true
$main_form.Controls.Add($Label3)

$Label4 = New-Object System.Windows.Forms.Label
$Label4.Text = "Associated Apps:"
$Label4.Location = New-Object System.Drawing.Point(0,80)
$Label4.AutoSize = $true
$main_form.Controls.Add($Label4)

$Label5 = New-Object System.Windows.Forms.Label
$Label5.Text = ""
$Label5.Location = New-Object System.Drawing.Point(110,80)
$Label5.AutoSize = $true
$main_form.Controls.Add($Label5)

$Label6 = New-Object System.Windows.Forms.Label
$Label6.Text = "Licenses:"
$Label6.Location = New-Object System.Drawing.Point(0,120)
$Label6.AutoSize = $true
$main_form.Controls.Add($Label6)

$Label7 = New-Object System.Windows.Forms.Label
$Label7.Text = ""
$Label7.Location = New-Object System.Drawing.Point(110,120)
$Label7.AutoSize = $true
$main_form.Controls.Add($Label7)

# Create Button
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Point(400,10)
$Button.Size = New-Object System.Drawing.Size(120,23)
$Button.Text = "Check"
$main_form.Controls.Add($Button)

#Set what clicking button does
$Button.Add_Click({
    $Label3.Text = (Get-AzureADUser -SearchString $ComboBox.SelectedItem | Get-AzureADUserMembership).DisplayName #Get User membership
    $Label5.Text = (Get-AzureADUser -SearchString $ComboBox.SelectedItem | Get-AzureADUserAppRoleAssignment).ResourceDisplayName #Get Users Roles
    $Label7.Text = (Get-AzureADUser -SearchString $ComboBox.SelectedItem | Get-AzureADUserLicenseDetail).SkuPartNumber #Get User Licences Details
})

# Close Button
$closeButton = New-Object System.Windows.Forms.Button
$closeButton.Location = New-Object System.Drawing.Size(400,160)
$closeButton.Size = '120,23'
$closeButton.FlatStyle = 'Flat'
$closeButton.BackColor = 'Gray'
$closeFont = New-Object System.Drawing.Font('Calibri',11,[System.Drawing.FontStyle]::Bold)
$closeButton.Font = $closeFont
$closeButton.Text = 'Close'
$main_form.Controls.Add($closeButton)

$closeButton.Add_Click({$main_form.Tag = $main_form.Close()})

# display the form on the screen
$main_form.ShowDialog()


<##
    Powershell script with GUI that query's Microsoft Azure User Resources, Groups, Applications and Licensing.
    Written by AIP Solutions - hello@aipsolutions.tech 

##>