Run Windows PowerShell scripts first at computer startup, shutdown
Exécuter les scripts Windows PowerShell en premier au démarrage et à l’arrêt de l’ordinateur
Explanation
This policy setting determines whether Windows PowerShell scripts are run before non-Windows PowerShell scripts during computer startup and shutdown. By default, Windows PowerShell scripts run after non-Windows PowerShell scripts.
If you enable this policy setting, within each applicable Group Policy Object (GPO), Windows PowerShell scripts are run before non-Windows PowerShell scripts during computer startup and shutdown.
For example, assume the following scenario:
There are three GPOs (GPO A, GPO B, and GPO C). This policy setting is enabled in GPO A.
GPO B and GPO C include the following computer startup scripts:
GPO B: B.cmd, B.ps1
GPO C: C.cmd, C.ps1
Assume also that there are two computers, DesktopIT and DesktopSales.
For DesktopIT, GPOs A, B, and C are applied. Therefore, the scripts for GPOs B and C run in the following order for DesktopIT:
Within GPO B: B.ps1, B.cmd
Within GPO C: C.ps1, C.cmd
For DesktopSales, GPOs B and C are applied, but not GPO A. Therefore, the scripts for GPOs B and C run in the following order for DesktopSales:
Within GPO B: B.cmd, B.ps1
Within GPO C: C.cmd, C.ps1
Note: This policy setting determines the order in which computer startup and shutdown scripts are run within all applicable GPOs. You can override this policy setting for specific script types within a specific GPO by configuring the following policy settings for the GPO:
Computer Configuration\Policies\Windows Settings\Scripts (Startup/Shutdown)\Startup
Computer Configuration\Policies\Windows Settings\Scripts (Startup/Shutdown)\Shutdown
Ce paramètre de stratégie détermine si les scripts Windows PowerShell sont exécutés avant les scripts autres que Windows PowerShell au démarrage et à l’arrêt de l’ordinateur. Par défaut, les scripts Windows PowerShell sont exécutés après les scripts autres que Windows PowerShell.
Si vous activez ce paramètre de stratégie, dans chaque objet de stratégie de groupe (GPO) applicable, les scripts Windows PowerShell s’exécutent avant les scripts autres que Windows PowerShell au démarrage et à l’arrêt de l’ordinateur.
Par exemple, supposons le scénario suivant :
Nous disposons de trois objets de stratégie de groupe (GPO A, GPO B et GPO C). Ce paramètre de stratégie est activé dans l’objet GPO A.
Les objets GPO B et GPO C incluent les scripts suivants de démarrage de l’ordinateur :
GPO B : B.cmd, B.ps1
GPO C : C.cmd, C.ps1
Supposons également qu’il existe deux ordinateurs : BureauIT et BureauVentes.
Sur BureauIT, les objets de stratégie de groupe A, B et C sont appliqués. Ainsi, les scripts pour les objets GPO B et C s’exécutent dans l’ordre suivant pour l’ordinateur BureauIT :
Dans GPO B : B.ps1, B.cmd
Dans GPO C : C.ps1, C.cmd
Pour l’ordinateur BureauVentes, les objets GPO B et C sont appliqués, ce qui n’est pas le cas pour l’objet GPO A. Ainsi, les scripts des objets GPO B et C s’exécutent dans l’ordre suivant pour l’ordinateur BureauVentes :
Dans GPO B : B.cmd, B.ps1
Dans GPO C : C.cmd, C.ps1
Remarque : ce paramètre de stratégie détermine l’ordre d’exécution des scripts de démarrage et d’arrêt de l’ordinateur dans tous les objets GPO concernés. Vous pouvez remplacer ce paramètre de stratégie pour des types de scripts spécifiques d’un objet de stratégie de groupe spécifique en configurant les paramètres de stratégie suivants pour l’objet de stratégie de groupe :
Configuration ordinateur\Stratégies\Paramètres Windows\Scripts (démarrage/arrêt)\Démarrage
Configuration ordinateur\Stratégies\Paramètres Windows\Scripts (démarrage/arrêt)\Arrêt
Registry
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System- Value name
RunComputerPSScriptsFirst
| State | Value written |
|---|---|
| Enabled | REG_DWORD = 1 |
| Disabled | REG_DWORD = 0 |
PowerShell
PowerShell commands that write to the registry what the policy would write. Values in angle brackets (<…>) must be replaced.
Writing directly to the registry bypasses Group Policy: if a GPO manages this value, it will be rewritten at the next gpupdate; otherwise the value stays in place (the "tattooing" effect). Prefer a GPO or, locally, LGPO.exe. Run PowerShell as administrator for HKLM. Some policies need a restart or gpupdate /force.
Enable
# Enable: Scripts/Run_Computer_PS_Scripts_First
$k = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System'
if (-not (Test-Path -Path $k)) { New-Item -Path $k -Force | Out-Null }
Set-ItemProperty -Path $k -Name 'RunComputerPSScriptsFirst' -Value 1 -Type DWordDisable
# Disable: Scripts/Run_Computer_PS_Scripts_First
$k = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System'
if (-not (Test-Path -Path $k)) { New-Item -Path $k -Force | Out-Null }
Set-ItemProperty -Path $k -Name 'RunComputerPSScriptsFirst' -Value 0 -Type DWordRevert to "Not configured"
# Revert to "Not configured": Scripts/Run_Computer_PS_Scripts_First
$k = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System'
Remove-ItemProperty -Path $k -Name 'RunComputerPSScriptsFirst' -ErrorAction SilentlyContinue