Skip to content
This repository was archived by the owner on Dec 6, 2023. It is now read-only.

Commit 2c61259

Browse files
msmimartsdwheeler
authored andcommitted
New Application Proxy PowerShell sample scripts (#249)
* add ps1 files * update comments
1 parent bcd7172 commit 2c61259

15 files changed

+783
-0
lines changed
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This sample script assigns a group to a specific Azure AD Application Proxy application.
2+
#
3+
# .\assign-group-to-app.ps1 -ServicePrincipalObjectId <ObjectId of the Azure AD Application Proxy application service principal> -GroupObjectId <ObjectId of the group>
4+
#
5+
# Tip: You can identify the parameters by using the following PS commands:
6+
# ServicePrincipalObjectId - Get-AzureADServicePrincipal -SearchString "<display name of the app>"
7+
# GroupObjectId - Get-AzureADGroup -SearchString "<name of the group>"
8+
#
9+
# This script requires PowerShell 5.1 (x64) and one of the following modules:
10+
# AzureAD 2.0.2.52
11+
# AzureADPreview 2.0.2.53
12+
#
13+
# Before you begin:
14+
# Run Connect-AzureAD to connect to the tenant domain.
15+
# Required Azure AD role: Global Administrator
16+
17+
param(
18+
[string] $ServicePrincipalObjectId = "null",
19+
[string] $GroupObjectId = "null"
20+
)
21+
22+
$servicePrincipalObjectId = $ServicePrincipalObjectId
23+
$groupObjectId = $GroupObjectId
24+
25+
If (($servicePrincipalObjectId -eq "null") -or ($groupObjectId -eq "null")) {
26+
27+
Write-Host "Parameter is missing." -BackgroundColor "Black" -ForegroundColor "Green"
28+
Write-Host " "
29+
Write-Host ".\assign-group-to-app.ps1 -ServicePrincipalObjectId <ObjectId of the Azure AD Application Proxy application service principal> -GroupObjectId <ObjectId of the group>" -BackgroundColor "Black" -ForegroundColor "Green"
30+
Write-Host " "
31+
Write-Host "Hints:" -BackgroundColor "Black" -ForegroundColor "Green"
32+
Write-Host "You can easily identify the parameters by using the following PS commands:" -BackgroundColor "Black" -ForegroundColor "Green"
33+
Write-Host " "
34+
Write-Host "ServicePrincipalObjectId - Get-AzureADServicePrincipal -SearchString ""<display name of the app>"" " -BackgroundColor "Black" -ForegroundColor "Green"
35+
Write-Host "GroupObjectId - Get-AzureADGroup -SearchString ""<name of the group>""" -BackgroundColor "Black" -ForegroundColor "Green"
36+
37+
Exit
38+
}
39+
40+
41+
New-AzureADGroupAppRoleAssignment -ObjectId $groupObjectId -PrincipalId $groupObjectId -ResourceId $servicePrincipalObjectId -Id 18d14569-c3bd-439b-9a66-3a2aee01d14f
42+
43+
Write-Host ("")
44+
Write-Host ("Finished.") -BackgroundColor "Black" -ForegroundColor "Green"
45+
Write-Host ("")
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This sample script assigns a user to a specific Azure AD Application Proxy application.
2+
#
3+
# .\assign-user-to-app.ps1 -ServicePrincipalObjectId <ObjectId of the Azure AD Application Proxy application service principal> -GroupObjectId <ObjectId of the user>
4+
#
5+
# Tip: You can identify the parameters by using the following PS commands:
6+
# ServicePrincipalObjectId - Get-AzureADServicePrincipal -SearchString "<display name of the app>"
7+
# UserObjectId - Get-AzureADGroup -SearchString "<name of the group>"
8+
#
9+
# This script requires PowerShell 5.1 (x64) and one of the following modules:
10+
# AzureAD 2.0.2.52
11+
# AzureADPreview 2.0.2.53
12+
#
13+
# Before you begin:
14+
# Run Connect-AzureAD to connect to the tenant domain.
15+
# Required Azure AD role: Global Administrator
16+
17+
param(
18+
[string] $ServicePrincipalObjectId = "null",
19+
[string] $UserObjectId = "null"
20+
)
21+
22+
$servicePrincipalObjectId = $ServicePrincipalObjectId
23+
$userObjectId = $UserObjectId
24+
25+
If (($servicePrincipalObjectId -eq "null") -or ($userObjectId -eq "null")) {
26+
27+
Write-Host "Parameter is missing." -BackgroundColor "Black" -ForegroundColor "Green"
28+
Write-Host " "
29+
Write-Host ".\assign-user-to-app.ps1 -ServicePrincipalObjectId <ObjectId of the Azure AD Application Proxy application service principal> -UserObjectId <ObjectId of the User>" -BackgroundColor "Black" -ForegroundColor "Green"
30+
Write-Host " "
31+
Write-Host "Hints:" -BackgroundColor "Black" -ForegroundColor "Green"
32+
Write-Host "You can easily identify the parameters by using the following PS commands:" -BackgroundColor "Black" -ForegroundColor "Green"
33+
Write-Host " "
34+
Write-Host "ServicePrincipalObjectId - Get-AzureADServicePrincipal -SearchString ""<display name of the app>"" " -BackgroundColor "Black" -ForegroundColor "Green"
35+
Write-Host "UserObjectId - Get-AzureADUser -SearchString ""<name of the user>""" -BackgroundColor "Black" -ForegroundColor "Green"
36+
37+
Exit
38+
}
39+
40+
New-AzureADUserAppRoleAssignment -ObjectId $userObjectId -PrincipalId $userObjectId -ResourceId $servicePrincipalObjectId -Id 18d14569-c3bd-439b-9a66-3a2aee01d14f
41+
42+
Write-Host ("")
43+
Write-Host ("Finished.") -BackgroundColor "Black" -ForegroundColor "Green"
44+
Write-Host ("")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# This sample script displays users and groups assigned to the specified Application Proxy application.
2+
#
3+
# .\display-users-group-of-an-app.ps1 -ObjectId <ObjectId of the application>
4+
#
5+
# This script requires PowerShell 5.1 (x64) and one of the following modules:
6+
# AzureAD 2.0.2.52
7+
# AzureADPreview 2.0.2.53
8+
#
9+
# Before you begin:
10+
# Run Connect-AzureAD to connect to the tenant domain.
11+
# Required Azure AD role: Global Administrator or Application Administrator
12+
13+
param(
14+
[string] $ObjectId = "null"
15+
)
16+
17+
$aadapServPrincObjId=$ObjectId
18+
19+
If ($aadapServPrincObjId -eq "null") {
20+
21+
Write-Host "Parameter is missing." -BackgroundColor "Black" -ForegroundColor "Green"
22+
Write-Host " "
23+
Write-Host ".\display-users-group-of-an-app.ps1 -ObjectId <ObjectId of the application>" -BackgroundColor "Black" -ForegroundColor "Green"
24+
Write-Host " "
25+
26+
Exit
27+
}
28+
29+
Write-Host "Reading users. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
30+
31+
$users=Get-AzureADUser -Top 1000000
32+
33+
Write-Host "Reading groups. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
34+
35+
$groups = Get-AzureADGroup -Top 1000000
36+
37+
$aadapApp = $aadapServPrinc | ForEach-Object { $allApps -match $_.AppId }
38+
39+
Write-Host "Displaying users and groups assigned to the specified Application Proxy application..." -BackgroundColor "Black" -ForegroundColor "Green"
40+
Write-Host " "
41+
42+
try { $app = Get-AzureADServicePrincipal -ObjectId $aadapServPrincObjId}
43+
44+
catch {
45+
46+
Write-Host "Possibly the ObjetId is incorrect." -BackgroundColor "Black" -ForegroundColor "Red"
47+
Write-Host " "
48+
49+
Exit
50+
}
51+
52+
Write-Host ("Application: " + $app.DisplayName + "(ServicePrinc. ObjID:" + $aadapServPrincObjId + ")")
53+
Write-Host ("")
54+
Write-Host ("Assigned (directly and through group membership) users:")
55+
Write-Host ("")
56+
57+
$number=0
58+
59+
foreach ($item in $users) {
60+
61+
$listOfAssignments = Get-AzureADUserAppRoleAssignment -ObjectId $item.ObjectId
62+
63+
$assigned = $false
64+
65+
foreach ($item2 in $listOfAssignments) { If ($item2.ResourceID -eq $aadapServPrincObjId) { $assigned = $true } }
66+
67+
If ($assigned -eq $true) {
68+
Write-Host ("DisplayName: " + $item.DisplayName + " UPN: " + $item.UserPrincipalName + " ObjectID: " + $item.ObjectID)
69+
$number = $number + 1
70+
}
71+
}
72+
73+
Write-Host ("")
74+
Write-Host ("Number of (directly and through group membership) users: " + $number)
75+
Write-Host ("")
76+
Write-Host ("")
77+
Write-Host ("Assigned groups:")
78+
Write-Host ("")
79+
80+
$number=0
81+
82+
foreach ($item in $groups) {
83+
84+
$listOfAssignments = Get-AzureADGroupAppRoleAssignment -ObjectId $item.ObjectId
85+
86+
$assigned = $false
87+
88+
foreach ($item2 in $listOfAssignments) { If ($item2.ResourceID -eq $aadapServPrincObjId) { $assigned = $true } }
89+
90+
If ($assigned -eq $true) {
91+
Write-Host ("DisplayName: " + $item.DisplayName + " ObjectID: " + $item.ObjectID)
92+
$number=$number+1
93+
}
94+
}
95+
96+
97+
Write-Host ("")
98+
Write-Host ("Number of assigned groups: " + $number)
99+
Write-Host ("")
100+
101+
Write-Host ("")
102+
Write-Host ("Finished.") -BackgroundColor "Black" -ForegroundColor "Green"
103+
Write-Host ("")
104+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This sample script gets all Azure AD Application Proxy applications (AppId, Name of the app, ObjID).
2+
#
3+
# This script requires PowerShell 5.1 (x64) and one of the following modules:
4+
# AzureAD 2.0.2.52
5+
# AzureADPreview 2.0.2.53
6+
#
7+
# Before you begin:
8+
# Run Connect-AzureAD to connect to the tenant domain.
9+
# Required Azure AD role: Global Administrator or Application Administrator or Application Developer
10+
11+
Write-Host "Reading service principals. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
12+
13+
$aadapServPrinc = Get-AzureADServicePrincipal -Top 100000 | where-object {$_.Tags -Contains "WindowsAzureActiveDirectoryOnPremApp"}
14+
15+
Write-Host "Displaying the Azure AD Application Proxy applications." -BackgroundColor "Black" -ForegroundColor "Green"
16+
Write-Host " "
17+
18+
$aadapServPrinc | fl AppId, DisplayName, ObjectId
19+
20+
Write-Host " "
21+
Write-Host "Number of Azure AD Application Proxy Applications: ", $aadapServPrinc.Count
22+
Write-Host " "
23+
24+
Write-Host ("")
25+
Write-Host ("Finished.") -BackgroundColor "Black" -ForegroundColor "Green"
26+
Write-Host ("")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This sample script gets all Azure AD Application Proxy Connector groups with the assigned applications.
2+
#
3+
# This script requires PowerShell 5.1 (x64) and one of the following modules:
4+
# AzureAD 2.0.2.52
5+
# AzureADPreview 2.0.2.53
6+
#
7+
# Before you begin:
8+
# Run Connect-AzureAD to connect to the tenant domain.
9+
# Required Azure AD role: Global Administrator or Application Administrator
10+
11+
Write-Host "Reading service principals. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
12+
13+
$aadapServPrinc = Get-AzureADServicePrincipal -Top 100000 | where-object {$_.Tags -Contains "WindowsAzureActiveDirectoryOnPremApp"}
14+
15+
Write-Host "Reading Azure AD applications. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
16+
17+
$allApps = Get-AzureADApplication -Top 100000
18+
19+
Write-Host "Reading application. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
20+
21+
$aadapApp = $aadapServPrinc | ForEach-Object { $allApps -match $_.AppId}
22+
23+
Write-Host "Reading connector groups. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
24+
25+
$aadapConnectorGroups=Get-AzureADApplicationProxyConnectorGroup -Top 100000
26+
27+
Write-Host "Displaying connector groups and assigned applications..." -BackgroundColor "Black" -ForegroundColor "Green"
28+
Write-Host " "
29+
30+
foreach ($item in $aadapConnectorGroups)
31+
{
32+
33+
If ($item.ConnectorGroupType -eq "applicationProxy")
34+
{
35+
"Connector group: " + $item.Name+ " (Id: " + $item.Id+ ")";
36+
" ";
37+
38+
39+
foreach ($item2 in $aadapApp)
40+
{
41+
42+
$connector = Get-AzureADApplicationProxyApplicationConnectorGroup -ObjectId $item2.ObjectID;
43+
44+
If ($item.Id -eq $connector.Id)
45+
46+
{
47+
48+
$name = $aadapServPrinc -match $item2.AppId
49+
$name.DisplayName + " (AppId: " + $item2.AppId+ ")"}
50+
51+
}
52+
" ";
53+
}
54+
}
55+
56+
57+
Write-Host ("")
58+
Write-Host ("Finished.") -BackgroundColor "Black" -ForegroundColor "Green"
59+
Write-Host ("")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This sample script gets all Azure AD Application Proxy applications (AppId, Name of the app, external / internal url, authentication type).
2+
#
3+
# This script requires PowerShell 5.1 (x64) and one of the following modules:
4+
# AzureAD 2.0.2.52
5+
# AzureADPreview 2.0.2.53
6+
#
7+
# Before you begin:
8+
# Run Connect-AzureAD to connect to the tenant domain.
9+
# Required Azure AD role: Global Administrator or Application Administrator or Application Developer
10+
11+
Write-Host "Reading service principals. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
12+
13+
$aadapServPrinc = Get-AzureADServicePrincipal -Top 100000 | where-object {$_.Tags -Contains "WindowsAzureActiveDirectoryOnPremApp"}
14+
15+
Write-Host "Reading Azure AD applications. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
16+
17+
$allApps = Get-AzureADApplication -Top 100000
18+
19+
Write-Host "Reading application. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
20+
21+
$aadapApp = $aadapServPrinc | ForEach-Object { $allApps -match $_.AppId}
22+
23+
Write-Host "Displaying all Azure AD Application Proxy applications with configuration details..." -BackgroundColor "Black" -ForegroundColor "Green"
24+
Write-Host " "
25+
26+
foreach ($item in $aadapApp) {
27+
$aadapServPrinc[$aadapApp.IndexOf($item)].DisplayName + " (AppId: " + $aadapServPrinc[$aadapApp.IndexOf($item)].AppId + ")";
28+
Get-AzureADApplicationProxyApplication -ObjectId $item.ObjectId | fl ExternalUrl, InternalUrl,ExternalAuthenticationType
29+
}
30+
31+
Write-Host ("")
32+
Write-Host ("Finished.") -BackgroundColor "Black" -ForegroundColor "Green"
33+
Write-Host ("")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This sample script gets all Azure AD Proxy applications that have assigned an Azure AD policy (token lifetime) with policy details.
2+
# Reference:
3+
# Configurable token lifetimes in Azure Active Directory (Preview)
4+
# https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-configurable-token-lifetimes
5+
#
6+
# This script requires PowerShell 5.1 (x64) and one of the following modules:
7+
# AzureAD 2.0.2.52
8+
# AzureADPreview 2.0.2.53
9+
#
10+
# Before you begin:
11+
# Run Connect-AzureAD to connect to the tenant domain.
12+
# Required Azure AD role: Global Administrator or Application Administrator
13+
14+
Write-Host "Reading service principals. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
15+
16+
$aadapServPrinc = Get-AzureADServicePrincipal -Top 100000 | where-object {$_.Tags -Contains "WindowsAzureActiveDirectoryOnPremApp"}
17+
18+
Write-Host "Reading Azure AD applications. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
19+
20+
$allApps = Get-AzureADApplication -Top 100000
21+
22+
Write-Host "Displaying Azure AD Application Proxy applications with assigned Azure AD policies" -BackgroundColor "Black" -ForegroundColor "Green"
23+
Write-Host " "
24+
25+
foreach ($item in $aadapServPrinc) {
26+
27+
$policy=Get-AzureADServicePrincipalPolicy -Id $item.ObjectId
28+
29+
If (!([string]::IsNullOrEmpty($policy.Id))) {
30+
31+
Write-Host ("")
32+
33+
$item.DisplayName + " (AppId: " + $item.AppId + ")"
34+
35+
Write-Host ("")
36+
Write-Host ("Policy")
37+
38+
Get-AzureADPolicy -Id $policy.id | fl
39+
40+
Write-Host ("")
41+
42+
}
43+
}
44+
45+
Write-Host ("")
46+
Write-Host ("Finished.") -BackgroundColor "Black" -ForegroundColor "Green"
47+
Write-Host ("")
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This sample script gets all Azure AD Application Proxy Connector groups with the included connectors.
2+
#
3+
# This script requires PowerShell 5.1 (x64) and one of the following modules:
4+
# AzureAD 2.0.2.52
5+
# AzureADPreview 2.0.2.53
6+
#
7+
# Before you begin:
8+
# Run Connect-AzureAD to connect to the tenant domain.
9+
# Required Azure AD role: Global Administrator or Application Administrator
10+
11+
Write-Host "Reading connector groups. This operation might take longer..." -BackgroundColor "Black" -ForegroundColor "Green"
12+
13+
$aadapConnectorGroups = Get-AzureADApplicationProxyConnectorGroup -Top 100000
14+
15+
Write-Host "Displaying connector groups and connectors..." -BackgroundColor "Black" -ForegroundColor "Green"
16+
Write-Host " "
17+
18+
foreach ($item in $aadapConnectorGroups) {
19+
20+
If ($item.ConnectorGroupType -eq "applicationProxy") {
21+
22+
"Connector group: " + $item.Name, "(Id:" + $item.Id + ")";
23+
Get-AzureADApplicationProxyConnectorGroupMembers -Id $item.Id;
24+
" ";
25+
26+
}
27+
}
28+
29+
Write-Host ("")
30+
Write-Host ("Finished.") -BackgroundColor "Black" -ForegroundColor "Green"
31+
Write-Host ("")

0 commit comments

Comments
 (0)