Private/O365MFASupport/Get-MFAExchangeModulePath.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Function Get-MFAExchangeModulePath {
    <#
    .SYNOPSIS
    Returns the MFA Exchange Module directory path or an error on how to install the module

    .DESCRIPTION
    Returns the MFA Exchange Module directory path or an error on how to install the module

    .EXAMPLE
    Get-MFAExchangeModulePath

    .NOTES
    Supports Connect-MDSOffice365.ps1

    #>


    [OutputType('System.String')]
    [CmdletBinding()]
    param ()

    begin {}
    process    {
        Try {
            $getChildItemSplat = @{
                Path        = "$Env:LOCALAPPDATA\Apps\2.0\*\Microsoft.Exchange.Management.ExoPowershellModule.manifest"
                Recurse     = $true
                ErrorAction = 'SilentlyContinue'
                Verbose     = $false
            }
            $MFAExchangeModule = Get-ChildItem @getChildItemSplat | Select-Object -ExpandProperty DirectoryName

            If ($null -eq $MFAExchangeModule) {
                Throw "The Exchange Online MFA Module was not found!
https://docs.microsoft.com/en-us/powershell/exchange/exchange-online/connect-to-exchange-online-powershell/mfa-connect-to-exchange-online-powershell?view=exchange-ps"

            }

            $MFAExchangeModule
        }
        Catch {
            Write-Error $PSItem
        }
    }
    end {}
}