QDF QDF.it
Controlla. Analizza. Risolvi.
Registrati
Script QDF
← Torna agli script

Dominio • CMD

Aggiornamento e verifica criteri di gruppo

Aggiorna i criteri di dominio e genera report separati con le GPO recepite dall'utente connesso e dall'oggetto computer.

CompatibilitàWindows 10 e Windows 11 in dominio Active DirectoryPrivilegiStandardFile[QDF.it] dominio - Aggiornamento e verifica criteri di gruppo.cmd
Scarica script ↓
>_ sorgente
:: Titolo: Aggiornamento e verifica criteri di gruppo
:: Descrizione: Aggiorna i criteri di dominio e genera report separati con le GPO recepite dall'utente connesso e dall'oggetto computer.
:: Categoria: dominio
:: Compatibilita: Windows 10 e Windows 11 in dominio Active Directory
:: Amministratore: Richiesto solamente per la fase computer
@echo off
setlocal EnableExtensions
title QDF - Aggiornamento e verifica criteri di gruppo
color 0E

set "REPORTDIR=%PUBLIC%\Documents\QDF-GPO-%COMPUTERNAME%"
set "GPRESULT=gpresult.exe"
if /I "%PROCESSOR_ARCHITECTURE%"=="ARM64" if exist "%SystemRoot%\SysWOW64\gpresult.exe" set "GPRESULT=%SystemRoot%\SysWOW64\gpresult.exe"

if /I "%~1"=="computer" goto :fase_computer

cls
echo ===============================================================
echo       AGGIORNAMENTO E VERIFICA CRITERI DI GRUPPO
echo ===============================================================
echo.
echo Lo script aggiornera e analizzera separatamente:
echo - i criteri dell'utente attualmente connesso;
echo - i criteri dell'oggetto computer, con privilegi amministrativi.
echo.
echo I report saranno salvati in:
echo %REPORTDIR%
echo.
echo Non verranno eseguiti automaticamente riavvio o disconnessione.
echo.
choice /C SN /N /M "Continuare? [S/N]: "
if errorlevel 2 exit /b

if not exist "%REPORTDIR%\" md "%REPORTDIR%" >nul 2>&1
if not exist "%REPORTDIR%\" goto :errore_cartella

echo.
echo [1/4] Aggiornamento dei criteri dell'utente %USERDOMAIN%\%USERNAME%...
gpupdate.exe /target:user /force
set "ESITO_UPDATE_USER=%ERRORLEVEL%"

echo.
echo [2/4] Generazione dei report relativi all'utente...
"%GPRESULT%" /scope user /r >"%REPORTDIR%\GPO-Utente-%USERNAME%.txt" 2>&1
set "ESITO_RESULT_USER=%ERRORLEVEL%"
"%GPRESULT%" /scope user /h "%REPORTDIR%\GPO-Utente-%USERNAME%.html" /f >nul 2>&1
if errorlevel 1 set "ESITO_RESULT_USER=1"

echo.
echo [3/4] Richiesta dei privilegi per i criteri computer...
powershell.exe -NoProfile -Command "$p = Start-Process -FilePath '%ComSpec%' -ArgumentList '/d','/c','\"%~f0\" computer' -Verb RunAs -Wait -PassThru; exit $p.ExitCode"
set "ESITO_COMPUTER=%ERRORLEVEL%"

echo.
echo [4/4] Riepilogo...
if not "%ESITO_UPDATE_USER%"=="0" (
    color 0C
    echo ATTENZIONE: aggiornamento dei criteri utente non completato.
)
if not "%ESITO_RESULT_USER%"=="0" (
    color 0C
    echo ATTENZIONE: report dei criteri utente non completato.
)
if not "%ESITO_COMPUTER%"=="0" (
    color 0C
    echo ATTENZIONE: fase computer annullata o terminata con errori.
)

if "%ESITO_UPDATE_USER%%ESITO_RESULT_USER%%ESITO_COMPUTER%"=="000" (
    color 0A
    echo Aggiornamento e report completati correttamente.
)

echo.
echo Report disponibili in:
echo %REPORTDIR%
start "" explorer.exe "%REPORTDIR%"
echo.
pause
endlocal
exit /b

:fase_computer
fltmc >nul 2>&1
if errorlevel 1 exit /b 5

if not exist "%REPORTDIR%\" md "%REPORTDIR%" >nul 2>&1
if not exist "%REPORTDIR%\" exit /b 6

cls
echo ===============================================================
echo             FASE COMPUTER - CRITERI DI GRUPPO
echo ===============================================================
echo.
echo Aggiornamento dei criteri dell'oggetto %COMPUTERNAME%...
gpupdate.exe /target:computer /force
set "ESITO_UPDATE_PC=%ERRORLEVEL%"

echo.
echo Generazione del riepilogo computer...
"%GPRESULT%" /scope computer /r >"%REPORTDIR%\GPO-Computer-%COMPUTERNAME%.txt" 2>&1
set "ESITO_RESULT_PC=%ERRORLEVEL%"
"%GPRESULT%" /scope computer /h "%REPORTDIR%\GPO-Computer-%COMPUTERNAME%.html" /f >nul 2>&1
if errorlevel 1 set "ESITO_RESULT_PC=1"

if not "%ESITO_UPDATE_PC%%ESITO_RESULT_PC%"=="00" (
    color 0C
    echo.
    echo Fase computer terminata con uno o piu errori.
    timeout /t 5 >nul
    exit /b 1
)

color 0A
echo.
echo Criteri computer aggiornati e report generati.
timeout /t 3 >nul
exit /b 0

:errore_cartella
color 0C
echo.
echo ERRORE: impossibile creare la cartella dei report.
echo.
pause
endlocal
exit /b 1