Here's how we just did this:
created a text file with the line: C:\Windows\System32\shutdown.exe /l /f and then changed the extension to .cmd
then, created a local scheduled task to run that .cmd file after targeting the folder we want it to ultimately be in locally. For our example, we located the .cmd file in C:@installers\Scripts
Once we tested that the Scheduled Task worked, we exported it to an XML file.
We then put those files on a universally available/accessible share
Next step we created an OU and put the targeted machines in there. Created a GPO in that OU that first copied those files from the share to the local folder on the machine and set it to Update (in case we wanted to update the way either file functioned down the road.) We did this under the computer configuration. Then under user configuration, we created a scheduled task on logon to:
Run: pwsh.exe
Arguments: -ExecutionPolicy Bypass -File "\FILEPATH\AutoLogoff.ps1" or whatever you name your PS1 file
Start in: C:\Program Files\PowerShell\7\ (we have Powershell 7 installed in our image by default. You location may vary)
The Powershell file has a single line to import the XML scheduled task:
Register-ScheduledTask -Xml (Get-Content '\path to file\AutoLogoff.xml' | Out-String) -TaskName "AutoLogoff" -Force
Hope that helps