HelperFunctions.psm1



function RequireConnectAadSupport()
{
    if(-not $Global:AadSupport.Session.Active) 
    { 
        Write-Host "Please run 'Connect-AadSupport' first." -ForegroundColor Yellow
        throw "Running 'Connect-AadSupport' required"
    }
}

function GetTokenForMsGraph
{
    # Get Access Token
    $result = Get-AadTokenUsingAdal `
    -ResourceId $Global:AadSupport.Resources.MsGraph `
    -ClientId $Global:AadSupport.Clients.AzurePowershell.ClientId `
    -Redirect $Global:AadSupport.Clients.AzurePowershell.RedirectUri `
    -UserId $Global:AadSupport.Session.AccountId `
    -SkipServicePrincipalSearch `
    -HideOutput

    # Throw error if can't get Access Token
    if($result.Error) { throw $result.Error }

    # Return Access Token
    return $result.AccessToken
}


function GetTokenForAadGraph
{
    # Get Access Token
    $result = Get-AadTokenUsingAdal `
    -ResourceId $Global:AadSupport.Resources.AadGraph `
    -ClientId $Global:AadSupport.Clients.AzurePowershell.ClientId `
    -Redirect $Global:AadSupport.Clients.AzurePowershell.RedirectUri `
    -UserId $Global:AadSupport.Session.AccountId `
    -SkipServicePrincipalSearch `
    -HideOutput

    # Throw error if can't get Access Token
    if($result.Error) { throw $result.Error }

    # Return Access Token
    return $result.AccessToken
}


function Load-AadSupportAdalAssembly
{
    param(
        [string]$AdalPath = $Global:AadSupportAdalPath
    )

    #Attempt to load the assemblies. Without these we cannot continue so we need the user to stop and take an action
    Try
    {
        
        $Params = @{
            PSScriptRoot = $PSScriptRoot
            AadSupportAdalPath = $Global:AadSupportAdalPath
        }

        Invoke-AdalCommand -Command {
            Param($Params)
            [System.Reflection.Assembly]::LoadFrom($Params.AadSupportAdalPath) | Out-Null
        } -Parameters $Params

        Invoke-AdalCommand -Command {
            Param($Params)
            . "$($Params.PSScriptRoot)\Adal.Class.ps1" 
        } -Parameters $Params 
    }

    Catch
    {
        Write-Warning "Unable to load ADAL assemblies.`nUpdate the AzureAd module by running Install-Module AzureAd -Force -AllowClobber"
    }
} 

function Write-ObjectToHost
{
    [cmdletbinding()]
    param(
        # PowerShell Object to write all Properties to Host
        [Parameter(Mandatory=$True,Position=0,ValueFromPipeline = $true)]
        [psobject]
        $InputObject,
        $Depth=0    
    )

    $Type = $InputObject.GetType().Name
    
    if($Type -eq "Hashtable" -or $Type -eq "OrderedDictionary")
    {
        $InputObject = New-Object -TypeName PSObject -Property $InputObject
    }

    $Indent = ""
    for($i=0; $i -lt $Depth; $i++)
    {
        $Indent = $Indent + " "
    }

    foreach($object in $InputObject)
    {
        $Members = $object | Get-Member
        ForEach($Member in $Members)
        {
            if($Member.MemberType -eq "NoteProperty" -or $Member.MemberType -eq "Property")
            {
                Write-Host "$Indent $($Member.Name) : "  -NoNewline  -ForegroundColor Yellow

                if($InputObject.($Member.Name) -match "Collections")
                {
                    $Depth++
                    Write-Host ""
                    Write-ObjectToHost $Object.($Member.Name) -Depth $Depth
                    
                }
                else {
                    Write-Host $Object.($Member.Name)
                }
            }
            
        }

        Write-Host ""

    }
}

function Show-AadSupportStatusBar
{
    if(!$Global:AadSupport.StatusBar)
    {
        $Global:AadSupport.StatusBar = 0
    }

    if($Global:AadSupport.StatusBar % 10 -eq 0)
    {
        Write-Host "." -ForegroundColor Yellow -NoNewline
        $Global:AadSupport.StatusBar = 0
    }
    $Global:AadSupport.StatusBar++
}


function GetAadSpAppRoles
{
    param(
        [string]$ClientObjectId, 
        [AllowNull()][string]$ResourceObjectId
    )

    $ServiceAppRoleAssignedTo = Invoke-AadCommand -Command {
        Param($ClientObjectId)
        Get-AzureADServiceAppRoleAssignedTo -All $true -ObjectId $ClientObjectId
    } -Parameters $ClientObjectId

    if($ResourceObjectId)
    {
        $ResourceSp = Get-AadServicePrincipal -Id $ResourceObjectId
        $CurrentAppRoles = $ServiceAppRoleAssignedTo | where {$_.ResourceId -eq $ResourceObjectId}
    }

    else 
    {
        $CurrentAppRoles = $ServiceAppRoleAssignedTo 
    }
    
        # Out-put current App Roles
        if ($CurrentAppRoles) {

            

            $AppRolesView = @()
            foreach($AppRole in $CurrentAppRoles) 
            {
                $Resource = Get-AadServicePrincipal -Id $AppRole.ResourceId

                $AppRolesView += [PSCustomObject]@{
                    RoleId = $AppRole.Id
                    RoleValue = ($Resource.AppRoles | where {$_.Id -eq $AppRole.Id}).Value 
                    RoleAssignedId = $AppRole.ObjectId
                    ResourceDisplayName = $AppRole.ResourceDisplayName 
                }
            }

            return $AppRolesView
        }

    return
}


# ############################################################################
Function Convert-AadThumbprintToByteArray {
    [cmdletbinding()]

    param(
        [parameter(Mandatory=$true)]
        [String] $Thumbprint
    )

    Write-Verbose "Converting thumbrpint '$Thumbprint' to ByteArray" 

    $Bytes = [byte[]]::new($Thumbprint.Length / 2)

    For($i=0; $i -lt $Thumbprint.Length; $i+=2){
        $Bytes[$i/2] = [convert]::ToByte($Thumbprint.Substring($i, 2), 16)
    }

    return $Bytes
}

# ############################################################################
Function Convert-ByteArrayToThumbprint {

    [cmdletbinding()]
    param(
        [parameter(Mandatory=$true)]
        [Byte[]]
        $Bytes
    )

    $Thumbprint = [System.Text.StringBuilder]::new($Bytes.Length * 2)

    ForEach($byte in $Bytes){
        $Thumbprint.AppendFormat("{0:x2}", $byte) | Out-Null
    }

    return $Thumbprint.ToString()
}


function Base64UrlEncode($Value)
{
    return $Value.Replace("=", [String]::Empty).Replace('+', '-').Replace('/', '_')
}

function Base64UrlDecode($Value)
{
    while($Value.Length % 4 -ne 0)
    {
        $Value += "="
    }
    
    return $Value.Replace('-', '+').Replace('_', '/')

}


function ConvertFrom-Base64String
{
    param
    (
        [Parameter(Mandatory=$true)]
        [string]$base64string
    )

    return [System.Text.Encoding]::UTF8.GetString(([System.Convert]::FromBase64String($base64string)))
}


<# EXAMPLE USAGE
$MyParams = @{
    UserId = $AccountId
}
 
Invoke-AadCommand -Command {
    Param($params)
    Get-AzureADUser -ObjectId $params.UserId
} -Parameters $MyParams
#>


function Invoke-AadCommand
{
    
    [CmdletBinding()]
    Param(
        [Parameter(
            mandatory=$true,
            Position=0,
            ValueFromPipeline = $true
        )]
        [ScriptBlock]$Command,
        $Parameters
    )

    "Invoking Azure AD Runspace..." | Log-AadSupport 
    $Command | Log-AadSupport 

    if($Parameters) {
        "Params for Command..." | Log-AadSupport
        $Parameters | Log-AadSupport 
    }
    

    $Error.Clear()

    if(-not $Global:AadSupport.Session.Active)
    {
        Write-Host "Need to run Connect-AadSupport" -ForegroundColor Yellow
        throw "Not Authenticated Yet."
    }

    if(!$AccountId)
    {
        $AccountId = ""
    }

    # Get Token for AAD Graph to be used for Azure AD PowerShell
    $token = Get-AadTokenUsingAdal `
      -ResourceId $Global:AadSupport.Resources.AadGraph `
      -ClientId $Global:AadSupport.Clients.AzureAdPowershell.ClientId `
      -Redirect $Global:AadSupport.Clients.AzureAdPowershell.RedirectUri `
      -Tenant $Global:AadSupport.Session.TenantId `
      -UserId $Global:AadSupport.Session.AccountId `
      -Prompt "Never" `
      -SkipServicePrincipalSearch `
      -HideOutput

    $AadAccessToken = $token.AccessToken

    $token = $null
    # Get Token for MS Graph to be used for Azure AD PowerShell
    $token = Get-AadTokenUsingAdal `
    -ResourceId $Global:AadSupport.Resources.MsGraph `
    -ClientId $Global:AadSupport.Clients.AzureAdPowershell.ClientId `
    -Redirect $Global:AadSupport.Clients.AzureAdPowershell.RedirectUri `
    -Tenant $Global:AadSupport.Session.TenantId `
    -UserId $Global:AadSupport.Session.AccountId `
    -Prompt "Never" `
    -SkipServicePrincipalSearch `
    -HideOutput
  
    $MsGraphAccessToken = $token.AccessToken

    $ErrorHandlingBegin = {
        $Error.Clear()
    }

    $ErrorHandlingEnd = {
        return $Error
    }

    $ConnectParams = @{
        TenantId = $Global:AadSupport.Session.TenantId
        AzureEnvironmentName = $Global:AadSupport.Session.AzureEnvironmentName
        LogLevel = "Info"
        LogFilePath = "c:\AadSupportLogs\"
        AadAccessToken = $AadAccessToken
        MsAccessToken = $MsGraphAccessToken
        AccountId =$Global:AadSupport.Session.AccountId

    }

    Write-Verbose "Connect Parameters..."
    Write-Verbose $ConnectParams | ConvertTo-Json -Depth 99
    
    # IMPORT LOGGING IN RUNSPACE
    $GlobalParams = $Global:AadSupport

    $Global:AadCommandResult = $null

    $ScriptBlock = {
      Param(
          $ConnectParams,
          $AadCommand,
          $AadCommandParams,
          $AadSupport
      )

      Write-Verbose "Running Connect-AzureAd"

      # Connect to AAD PowerShell Module
      $session = Connect-AzureAd `
        -TenantId $ConnectParams.TenantId `
        -AzureEnvironmentName $ConnectParams.AzureEnvironmentName `
        -LogLevel $ConnectParams.LogLevel `
        -LogFilePath $ConnectParams.LogPath `
        -AadAccessToken $ConnectParams.AadAccessToken `
        -MsAccessToken $ConnectParams.MsAccessToken `
        -AccountId $ConnectParams.AccountId

      # Run the AAD PowerShell Command
      $Command = [scriptblock]::Create($AadCommand)

      $Results = Invoke-Command -ScriptBlock $Command -ArgumentList $AadCommandParams 
      $Return = $results | ConvertTo-Json -Depth 99
      return $Return
      
    }

    $Job = Start-Job -ScriptBlock $ScriptBlock -ArgumentList $ConnectParams, $Command, $Parameters, $Global:AadSupport

    $Results = $Job | Wait-Job | Receive-Job | ConvertFrom-Json
    return $Results

}


function Invoke-AadSupportRunspace
{
    [CmdletBinding()]
    Param(
        [Parameter(
            mandatory=$true,
            Position=0,
            ValueFromPipeline = $true
        )]
        $Command,
        $Parameters,
        $Runspace
    )

    Write-Host "Starting Runspace"

    "Invoking ADAL Runspace with Command..." | Log-AadSupport 
    $Command | Log-AadSupport 

    if($Parameters) {
        "Params for Command..." | Log-AadSupport
        $Parameters | Log-AadSupport 
    }

    $ErrorHandlingBegin = {
        $Error.Clear()
    }

    $ErrorHandlingEnd = {
         $Error
    }

    # Setup Runspace
    $RunspaceName = "AadSupportRunspace"
    $PowerShell = [powershell]::Create()

    $PowerShell.runspace = $Runspace.Instance
    $PowerShell.runspace.Name = $RunspaceName

    $RunspaceState = $PowerShell.runspace.RunspaceStateInfo.State
    if($RunspaceState -eq "BeforeOpen")
    {
        $PowerShell.runspace = $PowerShell.runspace.Open()
    }

    # Clear errors in runspace
    [void]$PowerShell.AddScript($ErrorHandlingBegin)

    # IMPORT LOGGING IN RUNSPACE
    $PowerShell.runspace.SessionStateProxy.SetVariable('GlobalParams',$Global:AadSupport)

    [void]$PowerShell.AddScript({
        $ImportLogging = "$($GlobalParams.Path)\LoggingFunctions.ps1"
        . $ImportLogging 
    })
    
    $PowerShell.Invoke()
    $PowerShell.Commands.Clear()

    # Lets start running our 'calling' commands in Runspace
    # Run Command
    Write-Host "$($PowerShell.runspace.RunspaceStateInfo.State)" -ForegroundColor Yellow
    [void]$PowerShell.AddScript($Command).AddArgument($Parameters)
    $RunCommand = $PowerShell.BeginInvoke()
    $PowerShell.Commands.Clear()

    # Get Errors inside runspace
    [void]$PowerShell.AddScript($ErrorHandlingEnd)
    $ErrorInsideRunspace = $PowerShell.Invoke()

    $PowerShell.Dispose()


    if($RunCommand)
    {
        $RunCommand | Log-AadSupport
        Write-Host "Runspace Complete"
        return $RunCommand
    }

    if($ErrorInsideRunspace)
    {
        $ErrorInsideRunspace | Log-AadSupport -Force
        Write-Host "Runspace Errors"
        return $ErrorInsideRunspace
    }

    Write-Host "Runspace unknown failure"
}


function Invoke-AdalCommand
{
    [CmdletBinding()]
    Param(
        [Parameter(
            mandatory=$true,
            Position=0,
            ValueFromPipeline = $true
        )]
        $Command,
        $Parameters
    )

    "Invoking ADAL Runspace with Command..." | Log-AadSupport 
    $Command | Log-AadSupport 

    if($Parameters) {
        "Params for Command..." | Log-AadSupport
        $Parameters | Log-AadSupport 
    }

    $ErrorHandlingBegin = {
        $Error.Clear()
    }

    $ErrorHandlingEnd = {
         $Error
    }

    # Setup Runspace
    $RunspaceName = "AadSupportAdal"
    $PowerShell = [powershell]::Create()

    IF(-not $Global:AadSupportAdalRunspace)
    {
        $Global:AadSupportAdalRunspace = [runspacefactory]::CreateRunspace()
    }

    $PowerShell.runspace = $Global:AadSupportAdalRunspace
    #$PowerShell.runspace = $Global:AadSupport.Runspace.Adal.Instance
    $PowerShell.runspace.Name = $RunspaceName

    $RunspaceState = $PowerShell.runspace.RunspaceStateInfo.State
    if($RunspaceState -eq "BeforeOpen")
    {
        $PowerShell.runspace = $PowerShell.runspace.Open()
    }

    # Clear errors in runspace
    [void]$PowerShell.AddScript($ErrorHandlingBegin)

    # IMPORT LOGGING IN RUNSPACE
    $PowerShell.runspace.SessionStateProxy.SetVariable('GlobalParams',$Global:AadSupport)

    [void]$PowerShell.AddScript({
        $ImportLogging = "$($GlobalParams.Path)\LoggingFunctions.ps1"
        . $ImportLogging 
    })
    
    $PowerShell.Invoke()
    $PowerShell.Commands.Clear()

    # Run Command
    [void]$PowerShell.AddScript($Command).AddArgument($Parameters)
    $RunCommand = $PowerShell.Invoke()
    $PowerShell.Commands.Clear()

    # Get Errors inside runspace
    [void]$PowerShell.AddScript($ErrorHandlingEnd)
    $ErrorInsideRunspace = $PowerShell.Invoke()

    $PowerShell.Dispose()


    if($RunCommand)
    {
        $RunCommand | Log-AadSupport
        return $RunCommand
    }

    if($ErrorInsideRunspace)
    {
        $ErrorInsideRunspace | Log-AadSupport -Force
        return $ErrorInsideRunspace
    }
}

<# TEST #>
<#
$Params = @{}
$MyCommand = {
    Param($params)
    try {
        return "TEST"
        $result = $Global:AdalContext.AcquireToken($params.ResourceId,$params.ClientId,$params.Redirect,$params.Prompt,$params.UserId, $params.ExtraQueryParams)
     
    }
    catch
    {
        $_
    }
    return $result.AccessToken
}
 
$myvar = $null
Invoke-AdalCommand -Command $MyCommand -Parameters $Params -OutVariable $myvar
 
$var
#>




<# EXAMPLE USAGE
$MyParams = @{
    UserId = $AccountId
}
 
Invoke-AadCommand -Command {
    Param($params)
    Get-AzureADUser -ObjectId $params.UserId
} -Parameters $MyParams
#>


function Invoke-AzureCommand
{
    
    [CmdletBinding()]
    Param(
        [Parameter(
            mandatory=$true,
            Position=0,
            ValueFromPipeline = $true
        )]
        $Command,
        $Parameters,
        $SubscriptionId
    )

    "Invoking Azure PSH... Runspace ID:" + $($Global:AadSupport.Runspace.AzureAd.Instance.Id) | Log-AadSupport 
    $Command | Log-AadSupport 

    if($Parameters) {
        "Params for Command..." | Log-AadSupport
        $Parameters | Log-AadSupport 
    }

    if($SubscriptionId) {
        "Azure Subscription ID..." | Log-AadSupport
        $SubscriptionId | Log-AadSupport 
    }
    
    $Error.Clear()

    # Get Token for AAD Graph to be used for Azure PowerShell
    $AadToken = Get-AadTokenUsingAdal `
      -ResourceId $Global:AadSupport.Resources.AadGraph `
      -ClientId $Global:AadSupport.Clients.AzureAdPowershell.ClientId `
      -Redirect $Global:AadSupport.Clients.AzureAdPowershell.RedirectUri `
      -Tenant $Global:AadSupport.Session.TenantId `
      -UserId $Global:AadSupport.Session.AccountId `
      -Prompt "Auto" `
      -SkipServicePrincipalSearch `
      -HideOutput

    # Get Token for Azure Graph to be used for Azure PowerShell
    $AzureToken = Get-AadTokenUsingAdal `
      -ResourceId $Global:AadSupport.Resources.AzureServiceApi `
      -ClientId $Global:AadSupport.Clients.AzurePowershell.ClientId `
      -Redirect $Global:AadSupport.Clients.AzurePowershell.RedirectUri `
      -Tenant $Global:AadSupport.Session.TenantId `
      -UserId $Global:AadSupport.Session.AccountId `
      -Prompt "Auto" `
      -SkipServicePrincipalSearch `
      -HideOutput

    $AzureGraphToken = Get-AadTokenUsingAdal `
    -ResourceId $Global:AadSupport.Resources.AzureRmApi `
    -ClientId $Global:AadSupport.Clients.AzurePowershell.ClientId `
    -Redirect $Global:AadSupport.Clients.AzurePowershell.RedirectUri `
    -Tenant $Global:AadSupport.Session.TenantId `
    -UserId $Global:AadSupport.Session.AccountId `
    -Prompt "Auto" `
    -SkipServicePrincipalSearch `
    -HideOutput

    if($token.Error)
    {
        return "Run Connect-AadSupport"
    }


    $AadAccessToken = $AadToken.AccessToken
    $AzureAccessToken = $AzureToken.AccessToken
    $AzureGraphAccessToken = $AzureGraphToken.AccessToken

    $ErrorHandlingBegin = {
        $Error.Clear()
    }

    $ErrorHandlingEnd = {
        $Error
    }

    $ConnectParams = @{
        TenantId = $Global:AadSupport.Session.TenantId
        AzureEnvironmentName = $Global:AadSupport.Session.AzureEnvironmentName
        AadAccessToken = $AadAccessToken
        GraphAccessToken = $AzureGraphAccessToken
        AzureAccessToken = $AzureAccessToken
        AccountId = $Global:AadSupport.Session.AccountId
        SubscriptionId = $SubscriptionId
    }



    $ConnectCommand = {
        Param($Params)
        Clear-AzContext -Force
        $AzureSession = Connect-AzAccount `
        -AccessToken $Params.AzureAccessToken `
        -GraphAccessToken $Params.AadAccessToken `
        -AccountId $Params.AccountId `
        -Tenant $Params.TenantId 
        return $AzureSession
    }

    $ConnectCommandWithSubscription = {
        Param($Params)
        Clear-AzContext -Force
        $AzureSession = Connect-AzAccount `
        -AccessToken $Params.AzureAccessToken `
        -GraphAccessToken $Params.AadAccessToken `
        -AccountId $Params.AccountId `
        -Tenant $Params.TenantId `
        -Subscription $Params.SubscriptionId
        return $AzureSession
    }

    # Set up runspace
    $PowerShell = [powershell]::Create()
    $PowerShell.runspace = $Global:AadSupport.Runspace.AzureAd.Instance
    $RunspaceState = $Global:AadSupport.Runspace.AzureAd.Instance.RunspaceStateInfo.State
    if($RunspaceState -eq "BeforeOpen")
    {
        $PowerShell.runspace = $Global:AadSupport.Runspace.AzureAd.Instance.Open()
    }
    
    # IMPORT LOGGING IN RUNSPACE
    [void]$PowerShell.AddScript($ErrorHandlingBegin)
    $PowerShell.runspace.SessionStateProxy.SetVariable('GlobalParams',$Global:AadSupport)

    [void]$PowerShell.AddScript({
        $ImportLogging = "$($GlobalParams.Path)\LoggingFunctions.ps1"
        . $ImportLogging 
    })
    
    $PowerShell.Invoke()
    $PowerShell.Commands.Clear()
    
    # Connect to Azure (Connect-AzAccountd)

    #$SessionAzureGraphAccessToken = $Global:AadSupport.Session.AzureGraphAccessToken
    #$SessionAzureAccessToken = $Global:AadSupport.Session.AzureAccessToken
    #$SessionAadAccessToken = $Global:AadSupport.Session.AadAccessToken

    #if($SessionAzureGraphAccessToken -ne $AzureGraphAccessToken -and $SessionAzureGraphAccessToken -ne $AzureAccessToken -and $SessionAadAccessToken -ne $AadAccessToken)
    #{
    if($SubscriptionId)
    {
        [void]$PowerShell.AddScript($ConnectCommandWithSubscription).AddArgument($ConnectParams)
    }
    else {
        [void]$PowerShell.AddScript($ConnectCommand).AddArgument($ConnectParams)
    }
        
    
    $RunConnectAzureAd = $PowerShell.Invoke()
    $PowerShell.Commands.Clear()
    
    #}

    # Update our cached access tokens
    #$Global:AadSupport.Session.AzureGraphAccessToken = $SessionAzureGraphAccessToken
    #$Global:AadSupport.Session.AzureAccessToken = $SessionAzureAccessToken
    #$Global:AadSupport.Session.AadAccessToken = $SessionAadAccessToken
    
    
    # Run command
    [void]$PowerShell.AddScript($Command).AddArgument($Parameters)
    $RunCommand = $PowerShell.Invoke()
    $PowerShell.Commands.Clear()

    # Get errors in runspace
    [void]$PowerShell.AddScript($ErrorHandlingEnd)
    $ErrorInsideRunspace = $PowerShell.Invoke()
    $PowerShell.Commands.Clear()

    if($RunCommand)
    {
        $RunCommand | Log-AadSupport
        return $RunCommand
    }

    if($ErrorInsideRunspace)
    {
        $ErrorInsideRunspace | Log-AadSupport -Force
        throw $ErrorInsideRunspace
    }
}


function Invoke-MSOnlineCommand
{
    
    param
    (
        [Parameter(
            mandatory=$true,
            Position=0,
            ValueFromPipeline = $true
        )]
        $Command,
        $Parameters

    )

    "Invkoking MsOnline PSH" | Log-AadSupport 
    $Command | Log-AadSupport 

    if($Parameters) {
        "Params for Command..." | Log-AadSupport
        $Parameters | Log-AadSupport 
    }

    $ConnectState = $Global:AadSupport.Runspace.MSOnline.Connected
    if(-not $ConnectState -and $Command -ne "Connect-MsolService")
    {
        try {
            Invoke-MSOnlineCommand -Command "Connect-MsolService"
        }
        catch {
            throw $_
        }
        
        $Global:AadSupport.Runspace.MSOnline.Connected = $true
    }

    $PowerShell = [powershell]::Create()
    $PowerShell.runspace = $Global:AadSupport.Runspace.MSOnline.Instance
    $RunspaceState = $Global:AadSupport.Runspace.MSOnline.Instance.RunspaceStateInfo.State
    if($RunspaceState -eq "BeforeOpen")
    {
        $PowerShell.runspace = $Global:AadSupport.Runspace.MSOnline.Instance.Open()
    }
    
    # IMPORT LOGGING IN RUNSPACE
    $PowerShell.runspace.SessionStateProxy.SetVariable('GlobalParams',$Global:AadSupport)

    [void]$PowerShell.AddScript({
        $ImportLogging = "$($GlobalParams.Path)\LoggingFunctions.ps1"
        . $ImportLogging 
    })
    
    $PowerShell.Invoke()
    $PowerShell.Commands.Clear()
    
    
    # Run command
    [void]$PowerShell.AddScript($Command).AddArgument($Parameters)
    $RunCommand = $PowerShell.Invoke()
    $PowerShell.Commands.Clear()

    # Get errors in runspace
    [void]$PowerShell.AddScript($ErrorHandlingEnd)
    $ErrorInsideRunspace = $PowerShell.Invoke()
    $PowerShell.Commands.Clear()

    if($RunCommand)
    {
        $RunCommand | Log-AadSupport
        return $RunCommand
    }

    if($ErrorInsideRunspace)
    {
        $ErrorInsideRunspace | Log-AadSupport -Force
        return $ErrorInsideRunspace
    }
    
    $PowerShell.Dispose()
}


function Log-AadSupport
{
    Param(
        [Parameter(
            mandatory=$true,
            Position=0,
            ValueFromPipeline = $true
        )]
        [AllowNull()]
        $Message="",
        [switch]$Force
    )

    if(-not $Message)
    {
        return
    }

    if($Message)
    {
        if($Force)
        {
            Write-Verbose $Message
            Log-AadSupportMessage -Message $Message -Force
        }
        else {
            Write-Verbose $Message
            Log-AadSupportMessage -Message $Message
        }
    }

}

function Log-AadSupportMessage
{
    Param(
        [Parameter(
            mandatory=$true,
            Position=0,
            ValueFromPipeline = $true
        )]
        $Message,
        [switch]$Force
    )

    if(-not $Message) {
        return
    }

    if(-not $GlobalParams -and $Global:AadSupport)
    {
        $GlobalParams = $Global:AadSupport
    }

    if($GlobalParams.Logging.Enabled -or $Force)
    {
        if($Message.GetType().ToString() -eq "System.Collections.Hashtable")
        {
            $Message = $Message | ConvertTo-Json
        }

        $LogFileName = $GlobalParams.Logging.FileName
        $LogPath = $GlobalParams.Logging.Path
        $Now = (Get-Date).ToUniversalTime()
        $Utc = Get-Date $Now -Format o
        $date = ($Utc).Replace(":","-").Replace(".","_")

        if(-not $LogFileName)
        {
            $LogFileName = "$($date.ToString()).txt"
            New-Item -Path $LogPath -Name $LogFileName -ItemType "file" -Force | Out-Null
            $GlobalParams.Logging.FileName = $LogFileName
        }

        $FullPath = "$LogPath/$LogFileName"

        Add-Content -Path $FullPath -Value "$date | " -Force -NoNewline
        Add-Content -Path $FullPath -Value $Message -Force
    }

}
# SIG # Begin signature block
# MIIjnAYJKoZIhvcNAQcCoIIjjTCCI4kCAQExDzANBglghkgBZQMEAgEFADB5Bgor
# BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG
# KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCC3NOjSXxJhSKSt
# lP/A4TMF2DUCTo88cOLj7e8bEj1g66CCDYEwggX/MIID56ADAgECAhMzAAAB32vw
# LpKnSrTQAAAAAAHfMA0GCSqGSIb3DQEBCwUAMH4xCzAJBgNVBAYTAlVTMRMwEQYD
# VQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdSZWRtb25kMR4wHAYDVQQKExVNaWNy
# b3NvZnQgQ29ycG9yYXRpb24xKDAmBgNVBAMTH01pY3Jvc29mdCBDb2RlIFNpZ25p
# bmcgUENBIDIwMTEwHhcNMjAxMjE1MjEzMTQ1WhcNMjExMjAyMjEzMTQ1WjB0MQsw
# CQYDVQQGEwJVUzETMBEGA1UECBMKV2FzaGluZ3RvbjEQMA4GA1UEBxMHUmVkbW9u
# ZDEeMBwGA1UEChMVTWljcm9zb2Z0IENvcnBvcmF0aW9uMR4wHAYDVQQDExVNaWNy
# b3NvZnQgQ29ycG9yYXRpb24wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
# AQC2uxlZEACjqfHkuFyoCwfL25ofI9DZWKt4wEj3JBQ48GPt1UsDv834CcoUUPMn
# s/6CtPoaQ4Thy/kbOOg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