Functions/Get-ActiveDirectory.ps1
function Get-ActiveDirectory { trap {Out-Error $_; continue;} $script:scannedADApplications = New-Object System.Collections.ArrayList; $allApplications = Get-AzureRmADApplication; $noOfApplicationsFound = $allApplications.Count; $noOfApplicationsProcessed = 0; Add-Log "Total no. of AD applications found: $noOfApplicationsFound"; foreach($application in $allApplications) { $applicationId = $application.ApplicationId; $applicationName = $application.DisplayName; Write-Progress -Activity "Scanning Active Directory" -Id 2 -CurrentOperation "Processing application: $applicationName" -Status "AD applications in current tenant: $noOfApplicationsProcessed of $noOfApplicationsFound" -PercentComplete (($noOfApplicationsProcessed/$noOfApplicationsFound)*100) $currentApplicationCredentials = Get-AzureRmADAppCredential -ApplicationId $applicationId; foreach($applicationCredential in $currentApplicationCredentials){ $scannedADApplication = New-Object PSObject; $scannedADApplication | add-member -MemberType NoteProperty -Name "ApplicationId" -Value $applicationId; $scannedADApplication | add-member -MemberType NoteProperty -Name "DisplayName" -Value $applicationName; $scannedADApplication | add-member -MemberType NoteProperty -Name "KeyId" -Value $applicationCredential.KeyId; $scannedADApplication | add-member -MemberType NoteProperty -Name "StartDate" -Value $applicationCredential.StartDate; $scannedADApplication | add-member -MemberType NoteProperty -Name "EndDate" -Value $applicationCredential.EndDate; $scannedADApplication | add-member -MemberType NoteProperty -Name "KeyType" -Value $applicationCredential.Type; $scannedADApplications.Add($scannedADApplication) | Out-Null; $noOfApplicationsProcessed++; Add-Log "Processed Active Directory: $applicationId - $applicationName"; } } Add-Log "Finished processing $noOfApplicationsProcessed active directory applications"; if($scannedADApplications){ Set-Output -outputData $scannedADApplications -outputFileName "ActiveDirectory"; } } |