Powershell Modules – AzureAD – “Get User’s Information “

Background

Now that we have “AzureAD” Powershell modules installed, let us play around with it.

First off, the let us review what type of information is returned on a Member Account.

 

Code

Outline

  1. Using CmdletBinding define our script argument list
  2. To connect to our “Tenants Domain“, Issue “Connect-AzureAD
  3. To get specific AD Accounts, call get-azureaduser and filter appropriately
    • Get the returned object type by issuing GetType().Fullname
    • Get the first item in the result list by issuing Select-Object -first 1
    • Get Object’s Property list by issuing Select-Object -Property *
    • Display PropertyList

 

Actual Code

 


[CmdletBinding()]
Param(
  [Parameter(Mandatory=$True,Position=1)]
   [string]$personName
	
)
Set-StrictMode -Version Latest;

#Connect to Azure AD
Connect-AzureAD

# get list of AD users that matches the name passed in
$objListofPerson = get-azureaduser -Filter "startswith(displayName,'$personName')"


# if List is empty, then say so
if (!$objListofPerson)
{
     "Object (objListofPerson) is null (empty)"
     return
}
 
# Keith Hill - Get Type name
# the-typename-and-inheritance-chain/
# http://rkeithhill.wordpress.com/2007/10/28/powershell-quicktip-using-pstypenames-to-see-# 
$strLog = "Type name is " + $objListofPerson.GetType().Fullname;
$strLog
 
# Get top item in list
$objPerson = $objListofPerson | Select-Object -first 1

# if List is empty, then say so
if (!$objPerson)
{
     "Object (objPerson) is null (empty)"
     return
}
 
#https://www.codykonior.com/2013/03/26/powershell-how-to-show-all-of-an-objects-properties-and-values/
$objPersonPropList = $objPerson | Select-Object -Property *

if (!$objPersonPropList)
{
	 "Object has no properties"
	 return
}

$objPersonPropList

Invoke

Syntax


powershell -file ./Office365AzureAccount.ps1 -personName "[personName]"

Sample


powershell -file ./Office365AzureAccount.ps1 -personName "Daniel Adeniji"

Output

Images

Image – 01

Image – 02

Image – 03

Image – 04

 

Tabulate

  1. Type
    • Type name is Microsoft.Open.AzureAD.Model.User

Source Code

GitHub

DanielAdeniji/Office365AzureADPowerShell
Link

 

References

  1. Microsoft Azure
    • Azure/Azure PowerShell
      • Connect-Azure
        Link
      • GetAzureADUser
        • GetAzureADUser
          Link
  2. PowerShell
    • PowerShell Parameters
      • Don Jones
        • Windows PowerShell: Defining Parameters
          Link
    • PowerShell Properties
      • Cody Konior
        • PowerShell: How to show all of an object’s properties and values
          Link
    • PowerShell List
      • Don Jones
        • How can I get just the first entry from a list of entries?
          Link
  3. AzureAD Powershell
    • GetAzureADUser
      • StackOverflow
        • Example of Get-AzureADUser [-Filter <String>] command
          Link

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s