Professional Documents
Culture Documents
Windows Server Active Directory Windows Clients Virtualization PowerShell Exchange Cloud Linux
Windows OS Hub / Group Policies / How to Run GPO Logon Script Only Once?
April 5, 2022 Active Directory Group Policies Windows 10 Windows Server 2019
Move your
Shop Now
website for free
godaddy.com
GPO logon scripts allow you to run a BAT or PowerShell script at computer startup or user logon/logoff. In some cases, an
administrator wants a particular script (command/program) to be run for each user or computer only once and not run at the
next logons.
To solve this task, you can use a standard logon script that checks for a certain flag on the computer. This can be a registry
parameter, a text file on the disk, etc.
For example, you want a certain code block to be executed only once at the first user log on to a computer.
REM Put your code here, which will be executed once Active Directory
:END
Group Policies
The script creates a small text file in a user’s profile when it is run for the first time. When the script is run
Exchange Server
for the next time through the GPO, it checks if the file exists on a disk. If it does, the script has already been
executed and the code doesn’t need to be run again. Microsoft 365
Azure
2. Open the domain Group Policy Management console ( gpmc.msc );
Windows 11
3. Create a new policy and link it to an OU with users (or computers, but then you have to enable the Loopback
Processing mode);
Windows 10
4. Go to User Configuration -> Windows Settings -> Scripts (Logon / Logoff);
Windows Server 2022
5. Select Logon;
6. Click Add and specify the path to your BAT file in SYSVOL ( \\woshub.com\SysVol\woshub.com\scripts ); Windows Server 2019
If the GPO with the script has not been applied, use the gpresult tool and troubleshooting methods
8. At the next user logs on to a computer, the main script code will not be executed. So, the script is actually applied to
Another way to run a script only once using GPO is to create a one-time task in the Task Scheduler.
1. Save your script file (it may be either a BAT file or a PowerShell script) to the Sysvol folder on the domain controller
( \\<your_domain_name>\SysVol\<your_domain_name>\scripts );
2. Create a new GPO, link it to the user’s OU, and open its settings;
3. Go to Preferences -> Control Panel Settings -> Scheduled Task -> New -> Immediate Task (At least
RECENT POSTS
Windows 7);
Administratre
genera
PowerShell Active Directory
ConditionsScrunasCommon
Preferences
WindowsSettinc
afLocalUsersa
]NetworkOpt
IPowerOptio
Securitycotons Finding Duplicate E-mail
Nopoliciessclected
2Printers whenrunnngthetask,usethetolomnguseraccoun
(SMTP) Addresses in
RegionalOpt
elScheduledTh
Runonlywhenuserisloggedor
Exchange
5. Open the Actions tab, click New, and specify the full UNC path to your script file in SYSVOL; January 27, 2023
6. Then go to the Common tab and check the Apply once and do not reapply option;
If you want to run PowerShell scripts through a GPO, you need to configure the PowerShell script execution policy or
Fix: Can’t Extend Volume in
use the -ExecutionPolicy Bypass option when running your script (see an example here).
Windows
January 12, 2023
SUBSCRIBE
0 comment 1
RELATED READING
nstall Internet Explorer Using Previous Command History in How to Install the PowerShell Active Enable Internet Explorer (IE) Compatibility Finding Duplicate E-mail (SMTP) Addresses How to Disable or Uninstall Internet Explorer
)... PowerShell Console Directory Module... Mode in Microsoft... in Exchange (IE)...
26, 2023 January 31, 2023 January 31, 2023 January 27, 2023 January 27, 2023 January 26, 2023
LEAVE A COMMENT
Your Comment
NOTIFY ME OF FOLLOWUP COMMENTS VIA E-MAIL. YOU CAN ALSO SUBSCRIBE WITHOUT COMMENTING.
POST COMMENT
Popular Posts
Configure Google Chrome Settings with Group Policy