Alkane Solutions
Alkane Solutions Fixed-Price Apps | Trusted IT Partner
Alkane Solutions | G-Cloud Supplier Alkane Solutions | Microsoft Partner

Main menu

Skip to primary content
Skip to secondary content
  • Application Packaging Services
    • Why Application Packaging?
    • MSIX Application Packaging Services
    • Application Packaging Service for the NHS
    • Application Packaging for MECM
    • Intune Application Packaging Services
    • Evergreen Application Packaging Services
  • About
    • Team
    • Case StudiesCase studies of the work we have done for our clients.
  • Contact Us
  • Log In
  • Register
  • Submit a Guest Post!
  • Recommended Reading
  • Fixed-Price Quote

Home - powershell login script


Running Powershell Login Scripts with Group Policy

Posted on January 16, 2021 by Kae
Reply

We’ve recently experienced issues related to running Powershell login scripts with Group Policy.  These were caused by delays in login script execution, and so this post details a more optimal approach to run your Powershell login scripts asynchronously.

Group Policy Login Scripts Not Running

I wrote a Powershell script to configure VMWare Horizon client connections.  It worked flawlessly when launched via the PowerShell Scripts tab.

Group Policy Login Script

But due to the nature of the vmware-view executable (called in the script), the script took several seconds to run.  And this delay caused other login scripts from other group policy objects not to run, or to only run on an intermittent basis!

I tried a few workarounds in my Powershell script.

I tried launching the vmware-view executable with Start-Process and not wait for the exit code.  But this didn’t work because the executable needed to run synchronously, multiple times throughout the script (it essentially configured connections in a file called prefs.txt) and hence this wouldn’t work.

I also tried launching my code as a script block in a background task using Start-Job.  But this didn’t work either because Start-Job seemed to suppress any output (writing to a text file, for example the prefs.txt file) and this in turn stopped vmware-view from correctly configuring the Horizon view client connections!

Running Powershell Login Scripts with Group Policy

The most reliable method of running Powershell login scripts with group policy asynchronously, without causing issues with other login scripts, was to use a good old batch file.

In my netlogon folder I included my Powershell script ‘HorizonClientConnections.ps1’ and a cmd file called ‘HorizonClientConnections.cmd’.

I launched the HorizonClientConnections.cmd file using the ‘Scripts’ tab in Group Policy, and the content of the CMD file was simply:

cmd /c START %windir%\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -File "%~dp0HorizonClientConnections.ps1"

Of course if you only needed to run a single cmdlet, you may also use something like this:

cmd /c START %windir%\System32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle Hidden -ExecutionPolicy Bypass -Command "Set-SmbClientConfiguration -FileInfoCacheLifetime 0 -FileNotFoundCacheLifetime 0 -DirectoryCacheLifetime 0 -Force; Restart-Service -Name LanmanWorkstation -Force;"
Posted in PowerShell | Tagged powershell login script | Leave a Reply

Recommended Reading

Over

10,000

Applications
Packaged

Over

18

Successful
Migrations

Over

50

Happy
Clients

Application Packaging Services in Manchester, UK.
12b Kennerleys Lane, Wilmslow, England, SK9 5EQ

Application Packaging Services in London, UK.
152-160 City Road, London, EC1V 2NX.

© Alkane Solutions Ltd 2025
Privacy Policy | Modern Slavery | LinkedIn | Blog Posts

APPLICATION PACKAGING QUOTE!

✔ Fixed Price.
✔ Experienced IT Professionals.
✔ Highly Competitive Prices.
✔ 12 Month Warranty.






    This will close in 0 seconds