Workspace Environment Management

Analyze logon duration using scripted tasks

Long logon times decrease user productivity and result in a poor user experience. As an administrator, you might want to get a detailed overview of logon times to identify processes that cause slow logons so that you can take remedial action accordingly.

To achieve this goal, you can use the script Analyze_Logon_Duration.ps1. It is a PowerShell script that queries the event log for every major event relating to the logon process. The script offers the following benefits and more:

  • It gives you a logon duration breakdown of a user’s most recent logon.
  • It displays all major sequential phases of the logon process and makes it easy to see which phase is slowing down the logon.
  • It lets you check whether there is a delay between the end of one phase and the start of the next.

To see more benefits, go to

Workspace Environment Management (WEM) provides you with a scripted task feature that automates the running of the script for you. All you need to do is configure a scripted task. A general workflow is as follows:

  1. Prepare relevant scripts
  2. Add a scripted task
  3. Configure the scripted task
  4. View the task execution report

Prepare relevant scripts

Prepare a zip file that contains the following two scripts:

Zip file containing scripts

In this example, the script Run_Analyze_Logon_Duration.ps1 contains the following content:


The following content is for reference only. Verify that the “DomainUser” is resolved correctly. Otherwise, the script will not work as expected.

$SessionID = (Get-Process -PID $pid).SessionID
$DomainUser =(Get-WMIObject -ClassName Win32_ComputerSystem).Username
& ((Split-Path $MyInvocation.InvocationName) + "\Analyze_Logon_Duration-0531.ps1") -DomainUser $DomainUser -SessionID $SessionID

Add a scripted task

The following information is supplemental to the guidance in Add a scripted task. To create a task that analyzes logon duration, follow the general guidance in that article, minding the details below.

In Web Console > Scripted Tasks, add the task as follows:

Add a scripted task

  • For File type, select ZIP.
  • Browse to the zip file to upload it and set the script Run_ Analyze_Logon_Duration.ps1 as the entry point.
  • The Grant permissions option is designed to add an extra layer of security to protect against attacks originating from untrusted scripts, which might otherwise pose security risks. The Analyze_Logon_Duration task must run in full access.

Configure the scripted task

The following information is supplemental to the guidance in Configure a scripted task. To configure the Analyze_Logon_Duration task, follow the general guidance in that article, minding the details below.

  1. Go to the relevant configuration set, navigate to Scripted Task Settings, and configure the Analyze_Logon_Duration task in General as follows:

    • WEM lets you decide whether to verify the signature before running the task. Signature verification is mandatory when the scripted task is granted full access. This ensures security by protecting the scripts from being compromised. The Filter and Task timeout settings are optional.

    Configure the scripted task in General

  2. In Triggers, configure triggers for the task.

    Configure the scripted task in Trigger

    • Use triggers to control when to run the task. Make sure that the task runs after machine startup. For example, you can create a “scheduled” trigger to schedule the running of the task and then assoicate the trigger with the task.

      Add a "scheduled" trigger

      Associate the "scheduled" trigger with the task

  3. In Parameters, choose whether to pass parameters to the task. In this example, you can skip this step.

  4. In Output, configure settings as follows:

    Configure the scripted task in Output

View the task execution report

After the task runs successfully, you can view the results by checking the reports. For more information, see Reports. In this example, you can see the following report:

Example report

You can use filters to narrow your view to relevant reports and then export them. For information about exporting reports, see Export reports. Based on the exported data, you can perform further analysis.

The following is an example of visualizing data of interest in Power BI. It shows a breakdown of the user’s logon duration.

Data visualization example


Logon performance optimization is one of the highlights of the Workspace Environment Management service. The feature can change the overall logon process to drastically reduce logon times. See Logon Optimization.

Analyze logon duration using scripted tasks