Services/Connect-SCCLegacy.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
48
49
50
51
52
53
Function Connect-SCCLegacy {

    <#
    .SYNOPSIS
    Creates a connection to Exchange online using Legacy Auth (BASIC)
 
    .DESCRIPTION
    Connecto to Security and Compliace Center in the Legacy Manner using Basic Authentication
 
    .LINK
    https://github.com/Canthv0/CloudConnect
 
    .PARAMETER Credential
    Credential Object used to connect to SCC.
    If not provided user will be prompted for it.
 
    .OUTPUTS
    None. Creates a PS session to SCC and imports it into the global scope
 
    .EXAMPLE
    Connect-SCCLegacy
 
    Will prompt for credentials and import Exchange PS Session into the global scope
 
    .EXAMPLE
    $Cred = Get-Credential
    Connect-SCCLegacy -Credential $Cred
 
    Will used the $cred credential to connect to Security and Compliance Center
 
    #>


    Param($Credential)    

    # If we don't have a credential then prompt for it
    $i = 0
    while (($Null -eq $Credential) -and ($i -lt 5)) {
        $Credential = Get-Credential -Message "Please provide your Security and Compliance Center Credentials"
        $i++
    }
    
    # If we still don't have a credentail object then abort
    if ($null -eq $Credential) {
        Write-Error -Message "Failed to get credentials" -ErrorAction Stop
    }
    
    # Check for a previous sesison and remove it
    Get-PSSession -name Legacy_SCC* | Remove-PSSession -Confirm:$false

    # Create and import the session
    $session = New-PSSession -Name Legacy_SCC -ConfigurationName Microsoft.Exchange -ConnectionUri "https://ps.compliance.protection.outlook.com/powershell-liveid/" -Credential $Credential -Authentication Basic -AllowRedirection
    Import-Module (Import-PSSession $Session -AllowClobber) -Global -WarningAction 'SilentlyContinue'
}