Open in the explorer

Run Windows PowerShell scripts first at user logon, logoff

Exécuter les scripts Windows PowerShell en premier à l’ouverture et à la fermeture de sessions utilisateur

Type
Computer and user
GPO path
Computer Configuration › Policies › Administrative Templates › System › Scripts User Configuration › Policies › Administrative Templates › System › Scripts FR: Configuration ordinateur › Stratégies › Modèles d'administration › Système › ScriptsFR: Configuration utilisateur › Stratégies › Modèles d'administration › Système › Scripts
Supported on
At least Windows Server 2008 R2 or Windows 7 FR: Au minimum Windows Server 2008 R2 ou Windows 7
ADMX file
Scripts.admx
Internal name
Scripts/Run_User_PS_Scripts_First

Explanation

This policy setting determines whether Windows PowerShell scripts are run before non-Windows PowerShell scripts during user logon and logoff. By default, Windows PowerShell scripts run after non-Windows PowerShell scripts.

If you enable this policy setting, within each applicable Group Policy Object (GPO), PowerShell scripts are run before non-PowerShell scripts during user logon and logoff.

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 user logon scripts:

GPO B: B.cmd, B.ps1
GPO C: C.cmd, C.ps1

Assume also that there are two users, Qin Hong and Tamara Johnston.
For Qin, GPOs A, B, and C are applied. Therefore, the scripts for GPOs B and C run in the following order for Qin:

Within GPO B: B.ps1, B.cmd
Within GPO C: C.ps1, C.cmd

For Tamara, GPOs B and C are applied, but not GPO A. Therefore, the scripts for GPOs B and C run in the following order for Tamara:

Within GPO B: B.cmd, B.ps1
Within GPO C: C.cmd, C.ps1

Note: This policy setting determines the order in which user logon and logoff 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:

User Configuration\Policies\Windows Settings\Scripts (Logon/Logoff)\Logon
User Configuration\Policies\Windows Settings\Scripts (Logon/Logoff)\Logoff

This policy setting appears in the Computer Configuration and User Configuration folders. The policy setting set in Computer Configuration takes precedence over the setting set in User Configuration.

French text from Windows 11 26H2

Ce paramètre de stratégie détermine si les scripts Windows PowerShell sont exécutés avant les scripts autres que Windows PowerShell à l’ouverture et à la fermeture de sessions utilisateur. 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 applicable, les scripts PowerShell s’exécutent avant les scripts non PowerShell à l’ouverture et à la fermeture de sessions utilisateur.

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 d’ouverture de session utilisateur :

GPO B : B.cmd, B.ps1
GPO C : C.cmd, C.ps1

Supposons également qu’il existe deux utilisateurs : Qin Hong et Tamara Johnston.
Pour Qin, les objets GPO A, B et C sont appliqués. Ainsi, les scripts des objets GPO B et C s’exécutent dans l’ordre suivant pour l’ordinateur Qin :

Dans GPO B : B.ps1, B.cmd
Dans GPO C : C.ps1, C.cmd

Pour l’ordinateur Tamara, 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 Tamara :

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 d’ouverture et de fermeture de sessions utilisateur dans tous les objets GPO applicables. Vous pouvez remplacer ce paramètre de stratégie pour des types de scripts spécifiques d’un certain objet GPO en configurant les paramètres de stratégie suivants pour l’objet GPO :

Configuration utilisateur\Stratégies\Paramètres Windows\Scripts (ouverture/fermeture de session)\Ouverture de session
Configuration utilisateur\Stratégies\Paramètres Windows\Scripts (ouverture/fermeture de session)\Fermeture de session Le paramètre de stratégie défini dans Configuration ordinateur prévaut sur celui qui est défini dans Configuration utilisateur.

Registry

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System
Value name
RunUserPSScriptsFirst
StateValue written
EnabledREG_DWORD = 1
DisabledREG_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.

Computer (HKLM)

Enable

# Enable: Scripts/Run_User_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 'RunUserPSScriptsFirst' -Value 1 -Type DWord

Disable

# Disable: Scripts/Run_User_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 'RunUserPSScriptsFirst' -Value 0 -Type DWord

Revert to "Not configured"

# Revert to "Not configured": Scripts/Run_User_PS_Scripts_First
$k = 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Policies\System'
Remove-ItemProperty -Path $k -Name 'RunUserPSScriptsFirst' -ErrorAction SilentlyContinue

User (HKCU)

Enable

Disable

Revert to "Not configured"

Availability