Using the PowerShell in Azure Active Directory to examine the accounts

%3CLINGO-SUB%20id%3D%22lingo-sub-1921489%22%20slang%3D%22en-US%22%3EUsing%20the%20PowerShell%20in%20Azure%20Active%20Directory%20to%20examine%20the%20accounts%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1921489%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Azure%20friends%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20used%20the%20PowerShell%20ISE%20for%20this%20configuration.%20But%20you%20are%20also%20very%20welcome%20to%20use%20Visual%20Studio%20Code%2C%20just%20as%20you%20wish.%26nbsp%3BPlease%20start%20with%20the%20following%20steps%20to%20begin%20the%20deployment%20(the%20Hashtags%20are%20comments)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23The%20first%20two%20lines%20have%20nothing%20to%20do%20with%20the%20configuration%2C%20but%20make%20some%20space%20below%20in%20the%20blue%20part%20of%20the%20ISE%3C%2FP%3E%3CP%3E%3CSTRONG%3ESet-Location%20C%3A%5CTemp%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EClear-Host%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%23We%26nbsp%3Bneed%26nbsp%3Bthe%26nbsp%3Bcmdlets%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EInstall-Module%26nbsp%3B-Name%26nbsp%3BAzureAD%26nbsp%3B-AllowClobber%26nbsp%3B-Force%26nbsp%3B-Verbose%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Sometimes%26nbsp%3Bthe%26nbsp%3Bmodule%26nbsp%3Bmust%26nbsp%3Bbe%26nbsp%3Bimported%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EImport-Module%26nbsp%3BAzureAD%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Username%26nbsp%3Band%26nbsp%3BPW%26nbsp%3Bfor%26nbsp%3BLogin%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%24Credential%26nbsp%3B%3D%26nbsp%3BGet-Credential%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Lets%26nbsp%3Bconnect%26nbsp%3Bto%26nbsp%3Bthe%26nbsp%3BAzure%26nbsp%3BActive%26nbsp%3BDirectory%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EConnect-AzureAD%26nbsp%3B-Credential%26nbsp%3B%24Credential%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23View%26nbsp%3Ball%26nbsp%3Baccounts%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzureADUser%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23View%26nbsp%3Ba%26nbsp%3Bspecific%26nbsp%3Baccount%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B-ObjectID%26nbsp%3Bjane.ford%40tomwechsler.xyz%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23View%26nbsp%3Badditional%26nbsp%3Bproperty%26nbsp%3Bvalues%26nbsp%3Bfor%26nbsp%3Bthe%26nbsp%3Bcmdlet%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B%7C%26nbsp%3BGet-Member%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23View%26nbsp%3Badditional%26nbsp%3Bproperty%26nbsp%3Bvalues%26nbsp%3Bfor%26nbsp%3Ba%26nbsp%3Bspecific%26nbsp%3Baccount%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B%7C%26nbsp%3BSelect%26nbsp%3BDisplayName%2CDepartment%2CUsageLocation%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23To%26nbsp%3Bsee%26nbsp%3Ball%26nbsp%3Bthe%26nbsp%3Bproperties%26nbsp%3Bfor%26nbsp%3Ba%26nbsp%3Bspecific%26nbsp%3Buser%26nbsp%3Baccount%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B-ObjectID%26nbsp%3Bjane.ford%40tomwechsler.xyz%26nbsp%3B%7C%26nbsp%3BSelect%26nbsp%3B*%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23As%26nbsp%3Banother%26nbsp%3Bexample%2C%26nbsp%3Bcheck%26nbsp%3Bthe%26nbsp%3Benabled%26nbsp%3Bstatus%26nbsp%3Bof%26nbsp%3Ba%26nbsp%3Bspecific%26nbsp%3Buser%26nbsp%3Baccount%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B-ObjectID%26nbsp%3Bjane.ford%40tomwechsler.xyz%26nbsp%3B%7C%26nbsp%3BSelect%26nbsp%3BDisplayName%2CUserPrincipalName%2CAccountEnabled%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23View%26nbsp%3Baccount%26nbsp%3Bsynchronization%26nbsp%3Bstatus%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B%7C%26nbsp%3BWhere%26nbsp%3B%7B%24_.DirSyncEnabled%26nbsp%3B-eq%26nbsp%3B%24true%7D%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Find%26nbsp%3Bcloud-only%26nbsp%3Baccounts%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B%7C%26nbsp%3BWhere%26nbsp%3B%7B%24_.DirSyncEnabled%26nbsp%3B-ne%26nbsp%3B%24false%7D%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23View%26nbsp%3Baccounts%26nbsp%3Bbased%26nbsp%3Bon%26nbsp%3Ba%26nbsp%3Bcommon%26nbsp%3Bproperty%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B%7C%26nbsp%3BWhere%26nbsp%3B%7B%24_.UsageLocation%26nbsp%3B-eq%26nbsp%3B%24Null%7D%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23List%26nbsp%3Ball%26nbsp%3Baccounts%26nbsp%3Bof%26nbsp%3Busers%26nbsp%3Bwho%26nbsp%3Blive%26nbsp%3Bin%26nbsp%3BLondon%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B%7C%26nbsp%3BWhere%26nbsp%3B%7B%24_.City%26nbsp%3B-eq%26nbsp%3B%22London%22%7D%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ENow%20you%20have%20used%20the%20PowerShell%20to%20view%20Azure%20Active%20Directory%20Accounts!%20Congratulations!%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CDIV%3E%3CP%3EI%20hope%20this%20article%20was%20useful.%20Best%20regards%2C%20Tom%20Wechsler%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EP.S.%26nbsp%3BAll%20scripts%20(%23PowerShell%2C%20Azure%20CLI%2C%20%23Terraform%2C%20%23ARM)%20that%20I%20use%20can%20be%20found%20on%20github!%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Ftomwechsler%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Ftomwechsler%3C%2FA%3E%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1921489%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EHands-on-Labs%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Frequent Contributor

 

Hi Azure friends,

 

I used the PowerShell ISE for this configuration. But you are also very welcome to use Visual Studio Code, just as you wish. Please start with the following steps to begin the deployment (the Hashtags are comments):

 

#The first two lines have nothing to do with the configuration, but make some space below in the blue part of the ISE

Set-Location C:\Temp
Clear-Host

 

#We need the cmdlets
Install-Module -Name AzureAD -AllowClobber -Force -Verbose

#Sometimes the module must be imported
Import-Module AzureAD

#Username and PW for Login
$Credential = Get-Credential

#Lets connect to the Azure Active Directory
Connect-AzureAD -Credential $Credential

#View all accounts
Get-AzureADUser

#View a specific account
Get-AzureADUser -ObjectID jane.ford@tomwechsler.xyz

#View additional property values for the cmdlet
Get-AzureADUser | Get-Member

#View additional property values for a specific account
Get-AzureADUser | Select DisplayName,Department,UsageLocation

#To see all the properties for a specific user account
Get-AzureADUser -ObjectID jane.ford@tomwechsler.xyz | Select *

#As another example, check the enabled status of a specific user account
Get-AzureADUser -ObjectID jane.ford@tomwechsler.xyz | Select DisplayName,UserPrincipalName,AccountEnabled

#View account synchronization status
Get-AzureADUser | Where {$_.DirSyncEnabled -eq $true}

#Find cloud-only accounts
Get-AzureADUser | Where {$_.DirSyncEnabled -ne $false}

#View accounts based on a common property
Get-AzureADUser | Where {$_.UsageLocation -eq $Null}

#List all accounts of users who live in London
Get-AzureADUser | Where {$_.City -eq "London"}
 
Now you have used the PowerShell to view Azure Active Directory Accounts! Congratulations!
 

I hope this article was useful. Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler

0 Replies