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 https://www.controlup.com/script-library-posts/analyze-logon-duration/.
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:
- Prepare relevant scripts
- Add a scripted task
- Configure the scripted task
- View the task execution report
Prepare relevant scripts
Prepare a zip file that contains the following two scripts:
Analyze_Logon_Duration-0531.ps1. You can get this script from https://www.controlup.com/script-library-posts/analyze-logon-duration/.
Run_Analyze_Logon_Duration.ps1. This script is used as an entry point and passes relevant parameters to the script
Analyze_Logon_Duration-0531.ps1. You can customize this script as needed.
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 <!--NeedCopy-->
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:
- For File type, select ZIP.
- Browse to the zip file to upload it and set the script
Run_ Analyze_Logon_Duration.ps1as 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.
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.
In Triggers, configure triggers for the task.
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.
In Parameters, choose whether to pass parameters to the task. In this example, you can skip this step.
In Output, configure settings as follows:
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:
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.
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.