Private/O365MFASupport/Test-MDSModuleExist.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
46
47
Function Test-MDSModuleExist {
    <#
    .SYNOPSIS
    Test function to support Connect-Office365

    .DESCRIPTION
    Test function to support Connect-Office365

    .EXAMPLE
    Test-MDSModuleExist -Name $ModuleName -Item $ItemName

    .NOTES
    Cleans up some code in Connect-Office365

    #>


    [OutputType('System.Boolean')]
    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $True)]
        [ValidateNotNullOrEmpty()]
        [string]$Name,

        [Parameter(Mandatory = $True)]
        [ValidateNotNullOrEmpty()]
        [string]$Item
    )

    begin {}
    process {
        $getModuleSplat = @{
            Name          = $Name
            ListAvailable = $True
            ErrorAction   = 'SilentlyContinue'
            Verbose       = $False
        }
        If ($null -eq (Get-Module @getModuleSplat)) {
            Write-Error "The $Name module must be present to connect to $Item."
            $False
        }
        else {
            $True
        }
    }
    end {}
}