<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>get mfa method graph api Archives - the Sysadmin Channel</title>
	<atom:link href="https://thesysadminchannel.com/tag/get-mfa-method-graph-api/feed/" rel="self" type="application/rss+xml" />
	<link>https://thesysadminchannel.com/tag/get-mfa-method-graph-api/</link>
	<description>Documenting My Life as a System Administrator</description>
	<lastBuildDate>Mon, 07 Mar 2022 17:27:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
<site xmlns="com-wordpress:feed-additions:1">144174110</site>	<item>
		<title>Get MFA Methods using MSGraph API and PowerShell SDK</title>
		<link>https://thesysadminchannel.com/get-mfa-methods-using-msgraph-api-and-powershell-sdk/</link>
					<comments>https://thesysadminchannel.com/get-mfa-methods-using-msgraph-api-and-powershell-sdk/#comments</comments>
		
		<dc:creator><![CDATA[Paul Contreras]]></dc:creator>
		<pubDate>Tue, 15 Feb 2022 07:37:12 +0000</pubDate>
				<category><![CDATA[Graph API]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[get mfa method graph api]]></category>
		<category><![CDATA[Get MFA Methods using MSGraph API]]></category>
		<category><![CDATA[Get-MgUserAuthenticationMethod example]]></category>
		<guid isPermaLink="false">https://thesysadminchannel.com/?p=3806</guid>

					<description><![CDATA[<p>With the recent announcement of the Azure AD API deprecation, I&#8217;ve made an effort to try and migrate all of my scripts to use Microsoft Graph API. Microsoft Graph API is the latest standard for managing everything Microsoft 365 and&#8230; <a href="https://thesysadminchannel.com/get-mfa-methods-using-msgraph-api-and-powershell-sdk/" class="more-link">Continue Reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a href="https://thesysadminchannel.com/get-mfa-methods-using-msgraph-api-and-powershell-sdk/">Get MFA Methods using MSGraph API and PowerShell SDK</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>With the recent announcement of the Azure AD API deprecation, I&#8217;ve made an effort to try and migrate all of my scripts to use Microsoft Graph API.  Microsoft Graph API is the latest standard for managing everything Microsoft 365 and it is continuing to be developed for the foreseeable future. In this article, I&#8217;m going to share the script to <strong>Get MFA Methods using MSGraph API and PowerShell SDK</strong>.</p>
<p>Previously, I had to get this information using the old MSOnline (MSOL) module, however, since that is also deprecated, I thought it would be a good opportunity to freshen up my MSGraph skills and get this going.</p>
<div id="tableofcontents">
<h2>Table Of Contents</h2>
<ul>
<li><a href="#requirements">Requirements</a></li>
<li><a href="#parameters">Script Parameters</a></li>
<li><a href="#powershellscript">Get MFA Methods using MSGraph API</a></li>
<li><a href="#examples">Script Examples</a></li>
<li><a href="#conclusion">Conclusion</a></li>
</ul>
</div>
<div id="requirements" style="scroll-margin-top: 15px;"></div>
<h2>Requirements</h2>
<p>In order for this to work, there are a couple of requirements that need to be put in place prior to running the script.  While it is not a technical requirement, it would be ideal to have a basic understanding of Microsoft Graph API application and delegated permissions, scopes, apps, consent and maybe a sprinkle of Service Principals.<br />
&nbsp;</p>
<div id="blockquote1">
If you want to get started on learning how to use Microsoft Graph API, be sure to check out <a href="https://thesysadminchannel.com/how-to-connect-to-microsoft-graph-api-using-powershell/" rel="noopener" target="_blank">How To Connect To Microsoft Graph API Using PowerShell</a>.</p>
<p>This will cover everything you need to know and get you up and running in no time.
</p></div>
<p>Now for the actual technical requirements:</p>
<ul>
<li>An App/Service Principal to connect to Graph API -or granted consent to connect to Graph API as yourself</li>
<li>Microsoft.Graph PowerShell Module</li>
<li>Graph API Scopes (Delegated or Application permissions)</li>
<ul>
<li>UserAuthenticationMethod.Read.All</li>
<li>Directory.Read.All</li>
<li>User.Read.All</li>
</ul>
</ul>
<div id="parameters" style="scroll-margin-top: 15px;"></div>
<h2>Script Parameters</h2>
<h4>
<ul> UserId</ul>
</h4>
<p>Specify the UserPrincipalName or Id for the user you want to check authentication methods for.  </p>
<h4>
<ul> MethodType</ul>
</h4>
<p>Specify the method type you would like to filter for.  </p>
<div id="powershellscript" style="scroll-margin-top: 15px;"></div>
<h2>Get MFA Methods using MSGraph API</h2>
<p>Now let&#8217;s get to the PowerShell script. As mentioned, this is a function that will gather all of the authentication methods a user has registered for their account.  All Auth methods except for &#8220;Password Authentication&#8221; are strong authentication methods.  Another note, this uses <strong>Get-MgUserAuthenticationMethod</strong> under the hood and formats everything in a way that&#8217;s human readable.</p>
<pre class="brush: powershell; title: ; notranslate">
Function Get-MsGraphAuthenticationMethod {
&lt;#
.SYNOPSIS
    List MFA Authentication Methods for users using Graph API. A session using Connect-Graph must be open as a requirement.


.NOTES
    Name: Get-MsGraphAuthenticationMethod
    Author: paul@thesysadminchannel.com
    Version: 1.1
    DateCreated: 2021-Jan-20


.EXAMPLE
    Get-MsGraphAuthenticationMethod -UserId user1@domain.com, user2@domain.com


.EXAMPLE
    Get-MsGraphAuthenticationMethod -UserId user1@domain.com, user2@domain.com -MethodType MicrosoftAuthenticatorApp, EmailAuthencation

.LINK
    https://thesysadminchannel.com/get-mfa-methods-using-msgraph-api-and-powershell-sdk/ -
#&gt;

    [CmdletBinding()]
    param(
        [Parameter(
            Mandatory = $true,
            Position = 0
            )]
        [Alias('UserPrincipalName')]
        [string[]]  $UserId,


        [Parameter(
            Mandatory = $false
        )]
        [ValidateSet('AuthenticatorApp', 'PhoneAuthentication', 'Fido2', 'WindowsHelloForBusiness', 'EmailAuthentication', 'TemporaryAccessPass', 'Passwordless', 'SoftwareOath')]
        [string[]]   $MethodType
    )

    BEGIN {
        $ConnectionGraph = Get-MgContext
        if (-not $ConnectionGraph) {
            Write-Error &quot;Please connect to Microsoft Graph&quot; -ErrorAction Stop
        }

    }

    PROCESS {
        foreach ($User in $UserId) {
            try {
                $DeviceList = Get-MgUserAuthenticationMethod -UserId $User -ErrorAction Stop
                $DeviceOutput = foreach ($Device in $DeviceList) {

                    #Converting long method to short-hand human readable method type.
                    switch ($Device.AdditionalProperties[&quot;@odata.type&quot;]) {
                        '#microsoft.graph.microsoftAuthenticatorAuthenticationMethod'  {
                            $MethodAuthType     = 'AuthenticatorApp'
                            $AdditionalProperties = $Device.AdditionalProperties[&quot;displayName&quot;]
                        }

                        '#microsoft.graph.phoneAuthenticationMethod'                   {
                            $MethodAuthType     = 'PhoneAuthentication'
                            $AdditionalProperties = $Device.AdditionalProperties[&quot;phoneType&quot;, &quot;phoneNumber&quot;] -join ' '
                        }

                        '#microsoft.graph.passwordAuthenticationMethod'                {
                            $MethodAuthType     = 'PasswordAuthentication'
                            $AdditionalProperties = $Device.AdditionalProperties[&quot;displayName&quot;]
                        }

                        '#microsoft.graph.fido2AuthenticationMethod'                   {
                            $MethodAuthType     = 'Fido2'
                            $AdditionalProperties = $Device.AdditionalProperties[&quot;model&quot;]
                        }

                        '#microsoft.graph.windowsHelloForBusinessAuthenticationMethod' {
                            $MethodAuthType     = 'WindowsHelloForBusiness'
                            $AdditionalProperties = $Device.AdditionalProperties[&quot;displayName&quot;]
                        }

                        '#microsoft.graph.emailAuthenticationMethod'                   {
                            $MethodAuthType     = 'EmailAuthentication'
                            $AdditionalProperties = $Device.AdditionalProperties[&quot;emailAddress&quot;]
                        }

                        '#microsoft.graph.temporaryAccessPassAuthenticationMethod'        {
                            $MethodAuthType     = 'TemporaryAccessPass'
                            $AdditionalProperties = 'TapLifetime:' + $Device.AdditionalProperties[&quot;lifetimeInMinutes&quot;] + 'm - Status:' + $Device.AdditionalProperties[&quot;methodUsabilityReason&quot;]
                        }

                        '#microsoft.graph.passwordlessMicrosoftAuthenticatorAuthenticationMethod' {
                            $MethodAuthType     = 'Passwordless'
                            $AdditionalProperties = $Device.AdditionalProperties[&quot;displayName&quot;]
                        }

                        '#microsoft.graph.softwareOathAuthenticationMethod' {
                            $MethodAuthType     = 'SoftwareOath'
                            $AdditionalProperties = $Device.AdditionalProperties[&quot;displayName&quot;]
                        }
                    }

                    [PSCustomObject]@{
                        UserPrincipalName      = $User
                        AuthenticationMethodId = $Device.Id
                        MethodType             = $MethodAuthType
                        AdditionalProperties   = $AdditionalProperties
                    }
                }

                if ($PSBoundParameters.ContainsKey('MethodType')) {
                    $DeviceOutput | Where-Object {$_.MethodType -in $MethodType}
                  } else {
                    $DeviceOutput
                }

            } catch {
                Write-Error $_.Exception.Message

            } finally {
                $DeviceList           = $null
                $MethodAuthType       = $null
                $AdditionalProperties = $null

            }
        }
    }

    END {}

}
</pre>
<div id="examples" style="scroll-margin-top: 15px;"></div>
<h2>Script Examples</h2>
<p>Get-MsGraphAuthenticationMethod -UserId pcontreras@thesysadminchannel.com, buzz@thesysadminchannel.com</p>
<p><div id="attachment_3827" style="width: 1110px" class="wp-caption aligncenter"><a href="https://thesysadminchannel.com/wp-content/uploads/2022/02/Get-MFA-Methods-using-MSGraph-API-and-PowerShell-SDK-1.png" target="_blank" rel="noopener"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-3827" src="https://thesysadminchannel.com/wp-content/uploads/2022/02/Get-MFA-Methods-using-MSGraph-API-and-PowerShell-SDK-1.png" alt="Get MFA Methods using MSGraph API and PowerShell SDK" width="1100" height="367" class="size-full wp-image-3827" srcset="https://thesysadminchannel.com/wp-content/uploads/2022/02/Get-MFA-Methods-using-MSGraph-API-and-PowerShell-SDK-1.png?v=1644899115 1100w, https://thesysadminchannel.com/wp-content/uploads/2022/02/Get-MFA-Methods-using-MSGraph-API-and-PowerShell-SDK-1-1024x342.png?v=1644899115 1024w, https://thesysadminchannel.com/wp-content/uploads/2022/02/Get-MFA-Methods-using-MSGraph-API-and-PowerShell-SDK-1-768x256.png?v=1644899115 768w" sizes="(max-width: 1100px) 100vw, 1100px" /></a><p id="caption-attachment-3827" class="wp-caption-text">Display all authentication methods for both Paul and Buzz</p></div><br />
&nbsp;</p>
<p>Get-MsGraphAuthenticationMethod -UserId pcontreras@thesysadminchannel.com, buzz@thesysadminchannel.com -MethodType AuthenticatorApp, TemporaryAccessPass<br />
<div id="attachment_3828" style="width: 1051px" class="wp-caption aligncenter"><a href="https://thesysadminchannel.com/wp-content/uploads/2022/02/Get-MFA-Methods-using-MSGraph-API-and-PowerShell-SDK-2.png" target="_blank" rel="noopener"><img decoding="async" aria-describedby="caption-attachment-3828" src="https://thesysadminchannel.com/wp-content/uploads/2022/02/Get-MFA-Methods-using-MSGraph-API-and-PowerShell-SDK-2.png" alt="Get MFA Methods using MSGraph API and PowerShell SDK" width="1041" height="306" class="size-full wp-image-3828" srcset="https://thesysadminchannel.com/wp-content/uploads/2022/02/Get-MFA-Methods-using-MSGraph-API-and-PowerShell-SDK-2.png?v=1644899389 1041w, https://thesysadminchannel.com/wp-content/uploads/2022/02/Get-MFA-Methods-using-MSGraph-API-and-PowerShell-SDK-2-1024x301.png?v=1644899389 1024w, https://thesysadminchannel.com/wp-content/uploads/2022/02/Get-MFA-Methods-using-MSGraph-API-and-PowerShell-SDK-2-768x226.png?v=1644899389 768w" sizes="(max-width: 1041px) 100vw, 1041px" /></a><p id="caption-attachment-3828" class="wp-caption-text">Display only AuthenticatorApp and Temporary Access Pass method types</p></div></p>
<div id="conclusion" style="scroll-margin-top: 15px;"></div>
<h2>Conclusion</h2>
<p>Hopefully this script to Get MFA Methods using MSGraph API and PowerShell SDK would be useful to replace the legacy method of querying MSOnline to get the user&#8217;s strong auth methods.  Since this utilizes Microsoft Graph and REST APIs in the backend, it can work extremely fast with PowerShell 7 and Foreach-Object -Parallel.<br />
&nbsp;</p>
<p>I use this on a regular basis to see if a user has MFA enabled on their account.  The only downside so far is that it does not show the default method type, but I&#8217;m sure that&#8217;s somewhere down the pipeline.<br />
&nbsp;</p>
<p>If you liked this script and wanted to get more exposure to Graph API, I&#8217;ve just recently created the subreddit <a href="https://reddit.com/r/graphapi" rel="noopener" target="_blank">https://reddit.com/r/graphapi</a> for folks to who want to learn and ask questions.  I&#8217;m also going to be posting all my conversion scripts from the Azure AD module to GraphAPI so be sure check in time to time on our <a href="https://thesysadminchannel.com/powershell/graph-api/" rel="noopener" target="_blank">Graph API category posts</a></p>
<p>The post <a href="https://thesysadminchannel.com/get-mfa-methods-using-msgraph-api-and-powershell-sdk/">Get MFA Methods using MSGraph API and PowerShell SDK</a> appeared first on <a href="https://thesysadminchannel.com">the Sysadmin Channel</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://thesysadminchannel.com/get-mfa-methods-using-msgraph-api-and-powershell-sdk/feed/</wfw:commentRss>
			<slash:comments>12</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3806</post-id>	</item>
	</channel>
</rss>
