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

Main menu

Skip to primary content
Skip to secondary content
  • Hire Us
    • End User Compute
      • Software Services
      • Hardware Services
      • Licensing Services
      • Security Services
      • Support Services
    • Tooling and Automation
      • Bespoke Tooling Services
      • Robotic Process Automation Services
    • Web
      • Web Hosting Services
      • Web Development Services
    • Team
    • Case StudiesCase studies of the work we have done for our clients.
  • Contact Us
  • Log In
  • Register

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

Contact Us!

    Your Name (required)

    Your Email (required)

    Subject

    Your Message

    Over

    15,000

    Applications
    Packaged

    Over

    27

    Successful
    Migrations

    Over

    100

    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