Modules/Core/ARITestPS.psm1

<#
.Synopsis
Test Powershell environment
 
.DESCRIPTION
This module is use to test and validate the Powershell environment.
 
.Link
https://github.com/microsoft/ARI/Core/Test-PS.psm1
 
.COMPONENT
This powershell Module is part of Azure Resource Inventory (ARI)
 
.NOTES
Version: 4.0.1
First Release Date: 15th Oct, 2024
Authors: Claudio Merola
 
#>

function Test-ARIPS {
    Param($AzureEnvironment,$TenantID,$SubscriptionID,$DeviceLogin)
    Write-Debug ((get-date -Format 'yyyy-MM-dd_HH_mm_ss')+' - '+'Starting Test-PS function')
    $CShell = try{Get-CloudShellTip}catch{$null}
    if ($CShell) {
        Write-Output 'Azure CloudShell Identified.'
        $Global:Subscriptions = az account list --output json --only-show-errors | ConvertFrom-Json
        if ($SubscriptionID)
            {
                if($SubscriptionID.count -gt 1)
                    {
                        $Global:Subscriptions = $Subscriptions | Where-Object { $_.ID -in $SubscriptionID }
                    }
                else
                    {
                        $Global:Subscriptions = $Subscriptions | Where-Object { $_.ID -eq $SubscriptionID }
                    }
            }

        return 'Azure CloudShell'
    }
    else
    {
        if ($PSVersionTable.Platform -eq 'Unix') {
            Write-Output "PowerShell Unix Identified."
            Connect-LoginSession -AzureEnvironment $AzureEnvironment -TenantID $TenantID -SubscriptionID $SubscriptionID -DeviceLogin $DeviceLogin

            return 'PowerShell Unix'
        }
        else {
            Write-Output "PowerShell Desktop Identified."

            Connect-LoginSession -AzureEnvironment $AzureEnvironment -TenantID $TenantID -SubscriptionID $SubscriptionID -DeviceLogin $DeviceLogin

            return 'PowerShell Desktop'
        }
    }
}