Assign a logon/logoff script to a GPO by using PowerShell

Lingfei Wang 1 Reputation point
2021-04-08T01:01:30.36+00:00

I can assign a script to a GPO by using Group Policy Management and Group Policy Management Editor, and i can use PowerShell to create a new GPO, and link it to an OU, setting the policy by using cmdlet Set-GPRegistryValue. But I cannot find a way to assign a script to logon/logoff in the GPO.

I had tried to create the directory \domain\sysvol\domain\gp-guid\User\Scripts\Logon, copy the script into it, and then create the scripts.ini file under the User\Scripts. After this, you can see the configuration in Group Policy Management Editor. However, this configuration is not showed in the "Setting" tab page of the GPO in Group Policy Management. Moreover, it is not applied to the target users.

So, my question is how to assign a script to GPO by using PowerShell, or any other CLI tools?
Thanks!

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,794 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
{count} votes