Come controllare con PowerShell che la modern authentication sia abilitata in Office 365

di Team Ninja
Enable Modern Authentication in Office 365

La modern authentication è una funzione di sicurezza di Office 365 che utilizza Azure Active Directory (AAD) per autenticare gli utenti. Si pone come un faro di sicurezza, mettendo in ombra i metodi di autenticazione tradizionali come l'Autenticazione di base. Il motivo? La modern authentication si avvale di una crittografia più forte e di un livello di sicurezza aggiuntivo offerto dall'autenticazione a due fattori, che la rendono un meccanismo di difesa formidabile nel panorama informatico odierno.

Comprendere lo script per controllare la modern authentication

Lo script è stato progettato per controllare lo stato della modern authentication su tutti i profili degli utenti in un ambiente Office 365. Come si ottiene questo risultato? Esaminando meticolosamente ogni profilo utente sulla macchina e ispezionando i valori del registro di sistema legati alla modern authentication. Se lo script incontra un valore impostato su 0, è un chiaro indicatore che la modern authentication è disabilitata per quel profilo utente specifico.

Lo script

#Requires -Version 5.1

<#
.SYNOPSIS
    Monitors if user profiles have modern auth for Office 365 enabled or disabled.
.DESCRIPTION
    Monitors if user profiles have modern auth for Office 365 enabled or disabled.
    Check if HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\15.0\Common\Identity\EnableADAL is set to 1.
    Check if HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Common\Identity\EnableADAL is set to 0.
    Returns an exit code of 1 if one user has modern auth disabled.
    Returns an exit code of 0 if all user have modern auth enabled.
.EXAMPLE
     No parameter needed.
.OUTPUTS
    None
.NOTES
    Minimum OS Architecture Supported: Windows 10, Windows Server 2016
    Release Notes:
    Initial Release
    (c) 2023 NinjaOne
    By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/it/condizioni-utilizzo
    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
    Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#>

[CmdletBinding()]
param ()

begin {
    function Test-IsElevated {
        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
        $p = New-Object System.Security.Principal.WindowsPrincipal($id)
        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)
    }
}
process {
    if (-not (Test-IsElevated)) {
        Write-Error -Message "Access Denied. Please run with Administrator privileges."
        exit 1
    }
    # Loop through each user's profile
    # Check if HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\15.0\Common\Identity\EnableADAL is set to 1
    # Check if HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\16.0\Common\Identity\EnableADAL is set to 1

    $Path = @("SOFTWARE\Microsoft\Office\15.0\Common\Identity", "SOFTWARE\Microsoft\Office\16.0\Common\Identity")
    $Name = "EnableADAL"

    $Script:FoundModernAuthDisabled = $false

    # Get each user profile SID and Path to the profile
    $UserProfiles = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\*" |
        Where-Object { $_.PSChildName -match "S-1-5-21-(\d+-?){4}$" } |
        Select-Object @{Name = "SID"; Expression = { $_.PSChildName } }, @{Name = "UserHive"; Expression = { "$($_.ProfileImagePath)\NTuser.dat" } }, @{Name = "UserName"; Expression = { "$($_.ProfileImagePath | Split-Path -Leaf)" } }

    # Loop through each profile on the machine
    Foreach ($UserProfile in $UserProfiles) {
        # Load User ntuser.dat if it's not already loaded
        If (($ProfileWasLoaded = Test-Path -Path "Registry::HKEY_USERS\$($UserProfile.SID)") -eq $false) {
            Start-Process -FilePath "cmd.exe" -ArgumentList "/C reg.exe LOAD HKU\$($UserProfile.SID) $($UserProfile.UserHive)" -Wait -WindowStyle Hidden
        }

        # Read the user's registry
        $Path | ForEach-Object {
            $Key = Join-Path -Path "Registry::HKEY_USERS\$($UserProfile.SID)" -ChildPath $($_)
            $Value = Get-ItemProperty -Path $Key -ErrorAction SilentlyContinue | Select-Object $Name -ExpandProperty $Name -ErrorAction SilentlyContinue
            if (
                (
                    $_ -like "*15.0*" -and
                    $Value -ne 1 -and
                    $(Test-Path -Path $Key -ErrorAction SilentlyContinue)
                ) -or
                (
                    $_ -like "*16.0*" -and
                    $Value -eq 0
                )
            ) {
                Write-Host "$($UserProfile.UserName) ModernAuth is not enabled."
                $Script:FoundModernAuthDisabled = $true
            }
        }
 
        # Unload NTuser.dat
        If ($ProfileWasLoaded -eq $false) {
            [gc]::Collect()
            Start-Sleep 1
            Start-Process -FilePath "cmd.exe" -ArgumentList "/C reg.exe UNLOAD HKU\$($UserProfile.SID)" -Wait -WindowStyle Hidden | Out-Null
        }
    }
    if ($FoundModernAuthDisabled) {
        Write-Output $false
        exit 1
    }
    else {
        Write-Output $true
        exit 0
    }
}
end {}

 

Accedi a oltre 700 script nel Dojo di NinjaOne Ottieni l'accesso

Come i professionisti IT possono trarre vantaggio 

Lo script non è solo uno strumento, ma una soluzione su misura per i professionisti IT. Ecco come può cambiare le carte in tavola: 

  1. Monitoraggio proattivo: Prima che una potenziale falla nella sicurezza diventi un vero e proprio problema, lo script consente ai professionisti IT di identificare e risolvere i casi in cui la modern authentication è disabilitata. 
  2. L'efficienza al suo massimo livello: Il tempo è fondamentale nell'IT. Lo script automatizza il processo altrimenti noioso di controllo individuale di ogni profilo utente per verificare lo stato della modern authentication, liberando tempo prezioso. 
  3. Chiarezza e direzione: Niente più congetture. Lo script offre un’informazione certa su quali profili utente hanno la modern authentication abilitata e quali invece richiedono attenzione, aprendo la strada a una correzione mirata ed efficace.

NinjaOne: Il tuo partner nella gestione IT 

Sebbene lo script offra una soluzione mirata per verificare lo stato della modern authentication, la sua integrazione con una piattaforma di gestione IT completa come NinjaOne ne amplifica le capacità. NinjaOne offre una piattaforma unificata che semplifica le operazioni IT. Quando si tratta di modern authentication in Office 365, NinjaOne può eseguire lo script a intervalli programmati. Il risultato? Avvisi in tempo reale ai team IT su eventuali discrepanze, per garantire che la sicurezza non venga compromessa. 

Considerazioni finali 

Nel mondo dell'IT in continua evoluzione, la modern authentication in Office 365 non è solo una funzionalità disponibile, ma una necessità. Sfruttando lo script di cui abbiamo parlato e integrandolo con soluzioni solide come NinjaOne, i professionisti IT possono rafforzare le loro difese, assicurandosi che le loro organizzazioni siano sempre un passo avanti nella partita della sicurezza informatica.

Passi successivi

La creazione di un team IT efficiente ed efficace richiede una soluzione centralizzata che funga da principale strumento di erogazione dei servizi. NinjaOne consente ai team IT di monitorare, gestire, proteggere e supportare in termini di assistenza tutti i dispositivi, ovunque essi si trovino, senza la necessità di una complessa infrastruttura locale.
Scopri qualcosa in più su NinjaOne Endpoint Management, fai un tour dal vivo o inizia la tua prova gratuita della piattaforma NinjaOne.

NinjaOne si è classificato al primo posto per RMM, Endpoint Management e Patch Management

Monitora, gestisci e proteggi qualsiasi dispositivo, in qualsiasi luogo

NinjaOne gives you complete visibility and control over all your devices for more efficient management.

Un numero eccessivo di tool in location separate?

Scopri come la disseminazione di strumenti ha un impatto sull'IT e cosa si può fare per risolverla.