PowerShell – Detect AzureAD Device or Azure VDI

email me

Building upon the previous post, let’s extend our detection capability to include Azure VDI.

 
Code.ps1

# MrNetTek 
# eddiejackson.net 
# 9/11/2024
# free for public use 
# free to claim as your own

# Function to detect if FSLogix is installed
function Test-FSLogix {
    param (
        [string]$Path = "C:\Program Files\FSLogix"
    )
    return Test-Path $Path
}

# Function to detect if the machine is AzureAD joined
function Test-AzureADJoined {
    try {
        $dsregStatus = & dsregcmd /status 2>&1
        if ($dsregStatus -match "AzureAdJoined\s*:\s*YES") {
            return $true
        } else {
            return $false
        }
    } catch {
        Write-Error "Failed to execute dsregcmd: $_"
        return $false
    }
}

# Detect if FSLogix is installed
$FSLOGIXPath = "C:\Program Files\FSLogix"
$FSLOGIX = if (Test-FSLogix -Path $FSLOGIXPath) { "TRUE" } else { "FALSE" }

# Detect if AzureAD
$AzureAD = if (Test-AzureADJoined) { "TRUE" } else { "FALSE" }

# Output results
Write-Output "FSLogix Installed: $FSLOGIX"
Write-Output "AzureAD Joined: $AzureAD"