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

Powershell Modules – AzureAD – Installation

Background

Needing to do some minimal Microsoft Office 365 work.

Found out that I need Azure Powershell Modules.

Requirement

The Azure Active Directory ( AD) Powershell Modules are available on Microsoft’s Powershell Gallery.

Here is Microsoft’s write-up of what it takes to access the gallery and download modules from it:

Image

Azure Active Directory PowerShell for Graph
Link

Tabulate

Product Version Prerequisite
Operating System ( OS) Windows 10
Windows Management Framework ( WMF ) WMF v5.0
PackageManagement PowerShell Modules Preview – March 2016 v1.1 Powershell v3.0 or v4.0

 

Do we meet the requirement?

Let us do a quick check to determine whether we meet the requirement.

OS version

WinVer

From Console, issue winver

Syntax

winver

Output

Explanation

We are looking to have Windows Version 10, we are only at Version 7.

 

WMI Version

WMI Version – Using Powershell

From Console, run powershell and query $PSVersionTable

Syntax

Powershell -Command "$PSVersionTable"

Output

Explanation

We are looking to have WSManStackVersion be at v5.0, but we are only at v3.0.

 

Powershell – Module – PackageManagement

PackageManagement Powershell Modules

In Powershell issue “Get Module -ListAvailable

Syntax

powershell -Command "Get-Module -Name *Package* -ListAvailable"

Output

Explanation

We appear to be good with the Powershell Module Package Management.  The version installed is 1.*.

 

Meeting Requirement

If we did not meet the requirements, here are options to do so.

Windows Management Framework ( WMF )

Version

Version 5.1

As of 2018-Jan-21st, the latest version of WMF is 5.1 and it is available here.

Powershell – Module – PackageManagement

Go here and download the module that fits your your OS bitness.

 

Review Installation

Current

Let us quickly see whether we have the Azure Powershell Module installed.

Syntax

The module’s name is AzureAD and so we can look for anything bearing the Azure moniker.


powershell -Command "Get-Module -Name *Azure* -ListAvailable"

Output

Explanation

Nada

Actual Installation

Syntax


powershell -command "Install-module AzureAD"

Output

Explanation

We confirmed that we are OK with downloading modules from PSGallery.

 

Installation Validation

Syntax


Powershell -Command "Get-Module -Name *Azure* -ListAvailable"

Output

Explanation

We now have AzureAD installed.

The current version is 2.0.x.x

 

References

  1. Microsoft Azure
    • Azure PowerShell
      • Azure Active Directory PowerShell for Graph
        • Installation
        • How can I find the version of the Azure AD PowerShell module I’m using?
          Link