Created
July 11, 2018 11:03
-
-
Save JanVidarElven/175aad353e0311378068f5191a04587d to your computer and use it in GitHub Desktop.
AzureAutomationAuthToAzureADwithServicePrincipal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
This Azure Automation runbook connects to Azure AD with a Service Principal and Connect-AzureAD. | |
.DESCRIPTION | |
This Azure Automation runbook connects to Azure AD with a Service Principal and Connect-AzureAD. | |
It uses an Azure Run As Account connection that must be created before. | |
You have to import the AzureAD module from the Automation module gallery, if it's not already there. | |
AUTHOR: Jan Vidar Elven [MVP] | |
LASTEDIT: July 11th, 2018 | |
#> | |
# Get Azure Run As Connection Name | |
$connectionName = "AzureRunAsConnection" | |
# Get the Service Principal connection details for the Connection name | |
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName | |
# Logging in to Azure AD with Service Principal | |
"Logging in to Azure AD..." | |
Connect-AzureAD -TenantId $servicePrincipalConnection.TenantId ` | |
-ApplicationId $servicePrincipalConnection.ApplicationId ` | |
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint | |
"List Tenant Org Details:" | |
Get-AzureADTenantDetail | Select DisplayName, Street, PostalCode, City, CountryLetterCode | |
"Member Account Synced Count:" | |
(Get-AzureADUser -All $true -Filter "userType eq 'Member' and accountEnabled eq true" | Where-Object {$_.DirSyncEnabled -eq $true}).Count | |
"Disabled Users Count:" | |
(Get-AzureADUser -All $true -Filter 'accountEnabled eq false').Count | |
"Guest User Count:" | |
(Get-AzureADUser -All $true -Filter "userType eq 'Guest'").Count | |
"Cloud Only Account Count:" | |
(Get-AzureADUser -All $true -Filter "userType eq 'Member'" | Where-Object {$_.userPrincipalName -like "*onmicrosoft.com"}).Count | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment