Functions/Join-AppSettingActiveDirectory.ps1
function Join-AppSettingActiveDirectory{ $appSettingsCrossReferencedItems = New-Object System.Collections.ArrayList; $allWebApps = Get-AzureRmWebApp -ResourceGroupName $resourceGroupName; foreach($currentWebApp in $allWebApps){ $sitename = $currentWebApp.SiteName; $siteAppSettingsInfo = Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/Config -Name $sitename/appsettings -Action list -ApiVersion 2015-08-01 -Force $siteAppSettings = $siteAppSettingsInfo.Properties foreach($appSetting in $siteAppSettings.PSObject.Properties){ foreach($activeDirectoryApplication in $scannedADApplications){ if($activeDirectoryApplication.ApplicationId.ToString() -eq $appSetting.Value){ $referencedApplication = New-Object PSObject; $referencedApplication | add-member -MemberType NoteProperty -Name "SiteName" -Value $sitename; $referencedApplication | add-member -MemberType NoteProperty -Name "SiteURL" -Value $currentWebApp.DefaultHostName; $referencedApplication | add-member -MemberType NoteProperty -Name "SiteResourceGroup" -Value $resourceGroupName; $referencedApplication | add-member -MemberType NoteProperty -Name "SiteConfigKey" -Value $appSetting.Name; $referencedApplication | add-member -MemberType NoteProperty -Name "ActiveDirectory_AppID" -Value $activeDirectoryApplication.ApplicationId; $referencedApplication | add-member -MemberType NoteProperty -Name "ActiveDirectory_DisplayName" -Value $activeDirectoryApplication.DisplayName; $referencedApplication | add-member -MemberType NoteProperty -Name "ActiveDirectory_StartDate" -Value $activeDirectoryApplication.StartDate; $referencedApplication | add-member -MemberType NoteProperty -Name "ActiveDirectory_EndDate" -Value $activeDirectoryApplication.EndDate; $appSettingsCrossReferencedItems.Add($referencedApplication) | Out-Null; } } } } if($appSettingsCrossReferencedItems){ Set-Output -outputData $appSettingsCrossReferencedItems -outputFileName "AppService_ActiveDirectory"; } } |