|
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. |
| 1 | +<################################################################################# |
| 2 | +DISCLAIMER: |
5 | 3 |
|
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 |
| -################################################################################# |
| 4 | +This is not an official PowerShell Script. We designed it specifically for the situation you have |
| 5 | +encountered right now. |
12 | 6 |
|
13 |
| -Connect-AzureAD |
| 7 | +Please do not modify or change any preset parameters. |
| 8 | +
|
| 9 | +Please note that we will not be able to support the script if it's changed or altered in any way |
| 10 | +or used in a different situation for other means. |
| 11 | +
|
| 12 | +This code-sample is provided "AS IS" without warranty of any kind, either expressed or implied, |
| 13 | +including but not limited to the implied warranties of merchantability and/or fitness for a |
| 14 | +particular purpose. |
| 15 | +
|
| 16 | +This sample is not supported under any Microsoft standard support program or service. |
| 17 | +
|
| 18 | +Microsoft further disclaims all implied warranties including, without limitation, any implied |
| 19 | +warranties of merchantability or of fitness for a particular purpose. |
| 20 | +
|
| 21 | +The entire risk arising out of the use or performance of the sample and documentation remains with |
| 22 | +you. |
| 23 | +
|
| 24 | +In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or |
| 25 | +delivery of the script be liable for any damages whatsoever (including, without limitation, damages |
| 26 | +for loss of business profits, business interruption, loss of business information, or other |
| 27 | +pecuniary loss) arising out of the use of or inability to use the sample or documentation, even if |
| 28 | +Microsoft has been advised of the possibility of such damages. |
| 29 | +#################################################################################> |
| 30 | + |
| 31 | +Connect-MgGraph -Scopes 'Application.ReadWrite.All' |
| 32 | + |
| 33 | +$Messages = @{ |
| 34 | + DurationNotice = @{ |
| 35 | + Info = @( |
| 36 | + 'The operation is running and will take longer the more applications the tenant has...' |
| 37 | + 'Please wait...' |
| 38 | + ) -join ' ' |
| 39 | + } |
| 40 | + Export = @{ |
| 41 | + Info = 'Where should the CSV file export to?' |
| 42 | + Prompt = 'Enter the full path in the format of <C:\Users\<USER>\Desktop\Users.csv>' |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +Write-Host $Messages.DurationNotice.Info -ForegroundColor yellow |
| 47 | + |
| 48 | +$Applications = Get-MgApplication -All |
14 | 49 |
|
15 |
| -$Applications = Get-AzureADApplication -all $true |
16 | 50 | $Logs = @()
|
17 | 51 |
|
18 |
| -foreach ($app in $Applications) { |
19 |
| - $AppName = $app.DisplayName |
20 |
| - $AppID = $app.objectid |
21 |
| - $ApplID = $app.AppId |
22 |
| - $AppCreds = Get-AzureADApplication -ObjectId $AppID | select PasswordCredentials, KeyCredentials |
23 |
| - $secret = $AppCreds.PasswordCredentials |
24 |
| - $cert = $AppCreds.KeyCredentials |
| 52 | +foreach ($App in $Applications) { |
| 53 | + $AppName = $App.DisplayName |
| 54 | + $AppID = $App.Id |
| 55 | + $ApplID = $App.AppId |
| 56 | + |
| 57 | + $AppCreds = Get-MgApplication -ApplicationId $AppID | |
| 58 | + Select-Object PasswordCredentials, KeyCredentials |
| 59 | + |
| 60 | + $Secrets = $AppCreds.PasswordCredentials |
| 61 | + $Certs = $AppCreds.KeyCredentials |
25 | 62 |
|
26 | 63 | ############################################
|
27 |
| - $Log = New-Object System.Object |
28 |
| - |
29 |
| - $Log | Add-Member -MemberType NoteProperty -Name "ApplicationName" -Value $AppName |
30 |
| - $Log | Add-Member -MemberType NoteProperty -Name "ApplicationID" -Value $ApplID |
31 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Secret Start Date" -Value $Null |
32 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Secret End Date" -value $Null |
33 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Certificate Start Date" -Value $Null |
34 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Certificate End Date" -value $Null |
35 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Owner" -Value $Null |
36 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Owner_ObjectID" -value $Null |
37 |
| - |
38 |
| - $Logs += $Log |
| 64 | + $Logs += [PSCustomObject]@{ |
| 65 | + 'ApplicationName' = $AppName |
| 66 | + 'ApplicationID' = $ApplID |
| 67 | + 'Secret Name' = $Null |
| 68 | + 'Secret Start Date' = $Null |
| 69 | + 'Secret End Date' = $Null |
| 70 | + 'Certificate Name' = $Null |
| 71 | + 'Certificate Start Date' = $Null |
| 72 | + 'Certificate End Date' = $Null |
| 73 | + 'Owner' = $Null |
| 74 | + 'Owner_ObjectID' = $Null |
| 75 | + } |
39 | 76 | ############################################
|
40 |
| - foreach ($s in $secret) { |
41 |
| - $StartDate = $s.StartDate |
42 |
| - $EndDate = $s.EndDate |
43 |
| - |
44 |
| - #$operation = $EndDate - $now |
45 |
| - #$ODays = $operation.Days |
46 |
| - |
47 |
| - $Owner = Get-AzureADApplicationOwner -ObjectId $app.ObjectId |
48 |
| - $Username = $Owner.UserPrincipalName -join ";" |
49 |
| - $OwnerID = $Owner.ObjectID -join ";" |
50 |
| - if ($owner.UserPrincipalName -eq $Null) { |
51 |
| - $Username = $Owner.DisplayName + " **<This is an Application>**" |
| 77 | + foreach ($Secret in $Secrets) { |
| 78 | + $StartDate = $Secret.StartDateTime |
| 79 | + $EndDate = $Secret.EndDateTime |
| 80 | + $SecretName = $Secret.DisplayName |
| 81 | + |
| 82 | + $Owner = Get-MgApplicationOwner -ApplicationId $App.Id |
| 83 | + $Username = $Owner.AdditionalProperties.userPrincipalName -join ';' |
| 84 | + $OwnerID = $Owner.Id -join ';' |
| 85 | + |
| 86 | + if ($null -eq $Owner.AdditionalProperties.userPrincipalName) { |
| 87 | + $Username = @( |
| 88 | + $Owner.AdditionalProperties.displayName |
| 89 | + '**<This is an Application>**' |
| 90 | + ) -join ' ' |
52 | 91 | }
|
53 |
| - if ($Owner.DisplayName -eq $null) { |
54 |
| - $Username = "<<No Owner>>" |
| 92 | + if ($null -eq $Owner.AdditionalProperties.displayName) { |
| 93 | + $Username = '<<No Owner>>' |
55 | 94 | }
|
56 | 95 |
|
57 |
| - $Log = New-Object System.Object |
| 96 | + $Logs += [PSCustomObject]@{ |
| 97 | + 'ApplicationName' = $AppName |
| 98 | + 'ApplicationID' = $ApplID |
| 99 | + 'Secret Name' = $SecretName |
| 100 | + 'Secret Start Date' = $StartDate |
| 101 | + 'Secret End Date' = $EndDate |
| 102 | + 'Certificate Name' = $Null |
| 103 | + 'Certificate Start Date' = $Null |
| 104 | + 'Certificate End Date' = $Null |
| 105 | + 'Owner' = $Username |
| 106 | + 'Owner_ObjectID' = $OwnerID |
| 107 | + } |
| 108 | + } |
58 | 109 |
|
59 |
| - $Log | Add-Member -MemberType NoteProperty -Name "ApplicationName" -Value $AppName |
60 |
| - $Log | Add-Member -MemberType NoteProperty -Name "ApplicationID" -Value $ApplID |
61 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Secret Start Date" -Value $StartDate |
62 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Secret End Date" -value $EndDate |
63 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Certificate Start Date" -Value $Null |
64 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Certificate End Date" -value $Null |
65 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Owner" -Value $Username |
66 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Owner_ObjectID" -value $OwnerID |
| 110 | + foreach ($Cert in $Certs) { |
| 111 | + $StartDate = $Cert.StartDateTime |
| 112 | + $EndDate = $Cert.EndDateTime |
| 113 | + $CertName = $Cert.DisplayName |
67 | 114 |
|
68 |
| - $Logs += $Log |
69 |
| - } |
70 |
| - |
71 |
| - foreach ($c in $cert) { |
72 |
| - $CStartDate = $c.StartDate |
73 |
| - $CEndDate = $c.EndDate |
74 |
| - #$COperation = $CEndDate - $now |
75 |
| - #$CODays = $COperation.Days |
76 |
| - |
77 |
| - $Owner = Get-AzureADApplicationOwner -ObjectId $app.ObjectId |
78 |
| - $Username = $Owner.UserPrincipalName -join ";" |
79 |
| - $OwnerID = $Owner.ObjectID -join ";" |
80 |
| - if ($owner.UserPrincipalName -eq $Null) { |
81 |
| - $Username = $Owner.DisplayName + " **<This is an Application>**" |
| 115 | + $Owner = Get-MgApplicationOwner -ApplicationId $App.Id |
| 116 | + $Username = $Owner.AdditionalProperties.userPrincipalName -join ';' |
| 117 | + $OwnerID = $Owner.Id -join ';' |
| 118 | + |
| 119 | + if ($null -eq $Owner.AdditionalProperties.userPrincipalName) { |
| 120 | + $Username = @( |
| 121 | + $Owner.AdditionalProperties.displayName |
| 122 | + '**<This is an Application>**' |
| 123 | + ) -join ' ' |
82 | 124 | }
|
83 |
| - if ($Owner.DisplayName -eq $null) { |
84 |
| - $Username = "<<No Owner>>" |
| 125 | + if ($null -eq $Owner.AdditionalProperties.displayName) { |
| 126 | + $Username = '<<No Owner>>' |
85 | 127 | }
|
86 | 128 |
|
87 |
| - $Log = New-Object System.Object |
88 |
| - |
89 |
| - $Log | Add-Member -MemberType NoteProperty -Name "ApplicationName" -Value $AppName |
90 |
| - $Log | Add-Member -MemberType NoteProperty -Name "ApplicationID" -Value $ApplID |
91 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Certificate Start Date" -Value $CStartDate |
92 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Certificate End Date" -value $CEndDate |
93 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Owner" -Value $Username |
94 |
| - $Log | Add-Member -MemberType NoteProperty -Name "Owner_ObjectID" -value $OwnerID |
95 |
| - |
96 |
| - $Logs += $Log |
| 129 | + $Logs += [PSCustomObject]@{ |
| 130 | + 'ApplicationName' = $AppName |
| 131 | + 'ApplicationID' = $ApplID |
| 132 | + 'Secret Name' = $Null |
| 133 | + 'Certificate Name' = $CertName |
| 134 | + 'Certificate Start Date' = $StartDate |
| 135 | + 'Certificate End Date' = $EndDate |
| 136 | + 'Owner' = $Username |
| 137 | + 'Owner_ObjectID' = $OwnerID |
| 138 | + } |
97 | 139 | }
|
98 | 140 | }
|
99 | 141 |
|
100 |
| -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 |
101 |
| -$Path = Read-Host |
102 |
| -$Logs | Export-CSV $Path -NoTypeInformation -Encoding UTF8 |
| 142 | +Write-Host $Messages.Export.Info -ForegroundColor Green |
| 143 | +$Path = Read-Host -Prompt $Messages.Export.Prompt |
| 144 | +$Logs | Export-Csv $Path -NoTypeInformation -Encoding UTF8 |
0 commit comments