Skip to content

Commit 728f626

Browse files
authored
Adds app management and first sample script. (Azure#325)
1 parent f06ca22 commit 728f626

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#################################################################################
2+
#DISCLAIMER: This is not an official PowerShell Script. We designed it specifically for the situation you have encountered right now.
3+
#Please do not modify or change any preset parameters.
4+
#Please note that we will not be able to support the script if it is changed or altered in any way or used in a different situation for other means.
5+
6+
#This code-sample is provided "AS IT IS" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.
7+
#This sample is not supported under any Microsoft standard support program or service..
8+
#Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose.
9+
#The entire risk arising out of the use or performance of the sample and documentation remains with you.
10+
#In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the script be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample or documentation, even if Microsoft has been advised of the possibility of such damages.
11+
#################################################################################
12+
13+
Connect-AzureAD
14+
15+
$Applications = Get-AzureADApplication -all $true
16+
$Logs = @()
17+
18+
19+
foreach($app in $Applications)
20+
{
21+
$AppName = $app.DisplayName
22+
$AppID = $app.objectid
23+
$ApplID = $app.AppId
24+
$AppCreds = Get-AzureADApplication -ObjectId $AppID | select PasswordCredentials, KeyCredentials
25+
$secret = $AppCreds.PasswordCredentials
26+
$cert = $AppCreds.KeyCredentials
27+
28+
############################################
29+
$Log = New-Object System.Object
30+
31+
$Log | Add-Member -MemberType NoteProperty -Name "ApplicationName" -Value $AppName
32+
$Log | Add-Member -MemberType NoteProperty -Name "ApplicationID" -Value $ApplID
33+
$Log | Add-Member -MemberType NoteProperty -Name "Secret Start Date" -Value $Null
34+
$Log | Add-Member -MemberType NoteProperty -Name "Secret End Date" -value $Null
35+
$Log | Add-Member -MemberType NoteProperty -Name "Certificate Start Date" -Value $Null
36+
$Log | Add-Member -MemberType NoteProperty -Name "Certificate End Date" -value $Null
37+
38+
$Log | Add-Member -MemberType NoteProperty -Name "Owner" -Value $Null
39+
$Log | Add-Member -MemberType NoteProperty -Name "Owner_ObjectID" -value $Null
40+
$Logs += $Log
41+
############################################
42+
foreach($s in $secret)
43+
{
44+
$StartDate = $s.StartDate
45+
$EndDate = $s.EndDate
46+
47+
#$operation = $EndDate - $now
48+
#$ODays = $operation.Days
49+
50+
$Owner = Get-AzureADApplicationOwner -ObjectId $app.ObjectId
51+
$Username = $Owner.UserPrincipalName -join ";"
52+
$OwnerID = $Owner.ObjectID -join ";"
53+
if ($owner.UserPrincipalName -eq $Null)
54+
{
55+
$Username = $Owner.DisplayName + " **<This is an Application>**"
56+
}
57+
if ($Owner.DisplayName -eq $null)
58+
{
59+
$Username = "<<No Owner>>"
60+
}
61+
62+
$Log = New-Object System.Object
63+
64+
$Log | Add-Member -MemberType NoteProperty -Name "ApplicationName" -Value $AppName
65+
$Log | Add-Member -MemberType NoteProperty -Name "ApplicationID" -Value $ApplID
66+
$Log | Add-Member -MemberType NoteProperty -Name "Secret Start Date" -Value $StartDate
67+
$Log | Add-Member -MemberType NoteProperty -Name "Secret End Date" -value $EndDate
68+
$Log | Add-Member -MemberType NoteProperty -Name "Certificate Start Date" -Value $Null
69+
$Log | Add-Member -MemberType NoteProperty -Name "Certificate End Date" -value $Null
70+
71+
$Log | Add-Member -MemberType NoteProperty -Name "Owner" -Value $Username
72+
$Log | Add-Member -MemberType NoteProperty -Name "Owner_ObjectID" -value $OwnerID
73+
$Logs += $Log
74+
}
75+
76+
foreach($c in $cert)
77+
{
78+
$CStartDate = $c.StartDate
79+
$CEndDate = $c.EndDate
80+
#$COperation = $CEndDate - $now
81+
#$CODays = $COperation.Days
82+
83+
$Owner = Get-AzureADApplicationOwner -ObjectId $app.ObjectId
84+
$Username = $Owner.UserPrincipalName -join ";"
85+
$OwnerID = $Owner.ObjectID -join ";"
86+
if ($owner.UserPrincipalName -eq $Null)
87+
{
88+
$Username = $Owner.DisplayName + " **<This is an Application>**"
89+
}
90+
if ($Owner.DisplayName -eq $null)
91+
{
92+
$Username = "<<No Owner>>"
93+
}
94+
95+
$Log = New-Object System.Object
96+
97+
$Log | Add-Member -MemberType NoteProperty -Name "ApplicationName" -Value $AppName
98+
$Log | Add-Member -MemberType NoteProperty -Name "ApplicationID" -Value $ApplID
99+
$Log | Add-Member -MemberType NoteProperty -Name "Certificate Start Date" -Value $CStartDate
100+
$Log | Add-Member -MemberType NoteProperty -Name "Certificate End Date" -value $CEndDate
101+
102+
$Log | Add-Member -MemberType NoteProperty -Name "Owner" -Value $Username
103+
$Log | Add-Member -MemberType NoteProperty -Name "Owner_ObjectID" -value $OwnerID
104+
$Logs += $Log
105+
106+
}
107+
}
108+
109+
Write-host "Add the Path you'd like us to export the CSV file to, in the format of <C:\Users\<USER>\Desktop\Users.csv>" -ForegroundColor Green
110+
$Path = Read-Host
111+
$Logs | Export-CSV $Path -NoTypeInformation -Encoding UTF8

0 commit comments

Comments
 (0)