Performance Footprint of PowerShell Logon Scripts

PowerShell is a popular and extremely versatile tool, but is it a good idea to use PowerShell in logon scripts? Let’s try to find out!

Setting the Stage

I am going to compare the resource utilization of the following languages frequently used with logon scripts:

  • Batch
  • VBScript
  • PowerShell

How do you find the logon script’s duration and resource footprint? Such data is normally not too easy to come by, but uberAgent easily makes these and other logon metrics readily available.

Test Platform

All tests were performed on a virtual Windows Server 2012 R2, fully patched as of May 2015. Additional software: Citrix XenApp 7.6 VDA and uberAgent. The VM was equipped with 1 vCPU.

All measurements were taken in steady state, i.e. the machine had been booted up well in advance and I ignored the first logon because that basically puts all executables and DLLs from disk into RAM. During subsequent logons the disk is not used very much any more since all required files can be found in the operating system’s file system cache in RAM.

Test Scripts

I was interested in language overhead. That is why I was testing with very simple scripts that write the username to a text file.

Batch

Writing the username to a file is a one-liner in batch:

echo %username% > %temp%\username.txt

PowerShell

It is a one-liner in PowerShell, too:

$env:username > $env:temp\username2.txt

VBScript

VBScript requires an entire program to be written to accomplish the same task:

Set wshShell = CreateObject( "WScript.Shell" )
username = wshShell.ExpandEnvironmentStrings("%username%")
outFileName = wshShell.ExpandEnvironmentStrings("%temp%") & "\usernamevbs.txt"
Set outFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(outFileName,2,true)
outFile.WriteLine(username)
outFile.Close

Results

Script Runtime

The batch file and the VBScript are in the 0.3 to 0.4 second range, whereas the PowerShell script takes a whopping 4.5 seconds to execute. Factor batch - PowerShell: 16x.

PowerShell logon script performance - runtime

CPU Usage

The batch file and the VBScript are in the 60 to 80 CPU ms range, whereas the PowerShell script consumes 1,123 CPU ms. Factor VBScript - PowerShell: 18x.

PowerShell logon script performance - CPU time

Memory Consumption

The batch file and the VBScript are in the 20 to 24 MB range, whereas the PowerShell script needs 98 MB RAM. Factor batch - PowerShell: 5x.

PowerShell logon script performance - RAM

Conclusion

The total duration of the user logon is important to good user experience. With Citrix XenApp published applications logon speed even is critical. Logon script performance is often underestimated, partly due to the fact that Windows does not tell you how long a logon script took to execute and what the resource footprint was. uberAgent adds much needed visibility by providing detailed information about all aspects of the user logon. PowerShell is a great tool, but its resource footprint and runtime overhead make it a difficult recommendation for logon scripts which run at a point in time where many processes are competing for resources. Logon delays badly affect user experience. Any tools added to this phase should be as efficient as possible.

Comments

Related Posts

Blocking Office Macros, Managing Windows & macOS via Intune

Blocking Office Macros, Managing Windows & macOS via Intune
How to centrally manage essential security settings of self-managed devices This is a guest post by Martin Kretzschmar, customer success engineer at vast limits, the uberAgent company. One thing I especially like about my everyday working life is the flexibility it offers. I appreciate the freedom of choice in terms of location, time and device. We want to avoid getting into micro-management but, being an IT company, we also need to provide the necessary security where needed.
Scripting

PowerShell Script: Test Chrome, Firefox & IE Browser Performance

PowerShell Script: Test Chrome, Firefox & IE Browser Performance
There is more than one way to test the performance of web browsers like Chrome, Firefox, or IE, but regardless of how you do it, you need a consistent workload that makes the browsers comparable. Unless you are testing with synthetic benchmarks (which come with a plethora of problems of their own) you need a way to automate browsers opening tabs and loading URLs. This article presents a simple solution to do just that.
Scripting

Latest Posts

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage

Fast & Silent 5 Watt PC: Minimizing Idle Power Usage
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In the first post, I showed how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In this second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding

Fast & Silent 5 Watt PC: Lenovo ThinkCentre M90t Modding
This micro-series explains how to turn the Lenovo ThinkCentre M90t Gen 6 into a smart workstation that consumes only 5 Watts when idle but reaches top Cinebench scores while staying almost imperceptibly silent. In this first post, I’m showing how to silence the machine by replacing and adding to Lenovo’s CPU cooler. In a second post, I’m listing the exact configuration that achieves the lofty goal of combining minimal idle power consumption with top Cinebench scores.
Hardware