Get Task Sequence Feature Upgrade Split Times

Executing a lengthy In-Place-Upgrade Task Sequence within Microsoft Endpoint Configuration Manager and have been asked for a breakdown in timing for each of the Upgrade Steps to complete the Feature Update, then read on

Seen a few examples out there where others have been outputting the start and end times of a Task Sequence to a text file, so wanted to take this one step further and provide you with Split Timings of a running Task Sequence

The script will write to a comma-separated log file of each time it is called and then calculate the split time from the last time it was executed.

Create a Standard Package with a file containing the script ‘Get-TimeStamp.ps1

Get-TimeStamp.ps1 – Script also available at https://github.com/Drakey2000/CommunityHelper/tree/master/Get-TimeStamp

<#
.SYNOPSIS
    Enables you to add Task Sequence Task Steps and it will record the time it was initiated and calculate the duration
    of time passed from when it was last initiated

.DESCRIPTION
    Get-TimeStamp is a function that returns all time stamps and differencec from a running task sequnce

.PARAMETER State
    None


.EXAMPLE
     Get-TimeStamp

.OUTPUTS
    C:\Windows\Logs\ComputaCenter\TaskSequenceName-Timestamp.log

.NOTES
    Author:  Steven Drake
    Version: 1.0
#>

Try{
    # Import Microsoft.SMS.TSEnvironment
    $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment

    # Get Script Name - Without Extention
    $FileName = (Get-Item $PSCommandPath).Basename

    # Set Log File
    $Logfile = "$($env:windir)\CCM\Logs\_$($TSEnv.Value('_SMSTSPackageName'))-$FileName.log"

    # Create Log Folder
    New-Item -Path (Split-Path -Path $Logfile) -ItemType Directory -Force

    # Create Column Headers
    If(!(Test-Path -Path $Logfile)){Add-Content $Logfile -Value "Step Name,Start Timestamp,Duration Split - Days.Hrs.Mins:Secs"}

    # Get Current Time Stamp
    $CurrentTime=(Get-Date)

    # Get Running Step
    $Step = $TSEnv.Value('_SMSTSCurrentActionName')

    # Get Previous Time Stamp to Work Out Duration
    Try{

        # Calculate Time Split
        $Duration = (New-TimeSpan -Start $TSEnv.Value('LastTimeStamp') –End $CurrentTime)

        # Convert Time Split to Days. Hours : Minutes : Seconds
        $DurationString = "{0:dd}.{0:hh}:{0:mm}:{0:ss}" -f $Duration

    }Catch{}

    # Write TimeStamp Log - Comma Seperated
    Add-Content $Logfile -Value "$Step,$CurrentTime,$DurationString"

    # Update LastTimeStamp
    $TSEnv.Value('LastTimeStamp') = $CurrentTime

}Catch{ Add-Content $Logfile -Value $_.Exception.Message; Exit 1}




Then simply add a Run PowerShell script at every point in the Task Sequence you are looking to produce a Time Stamp for


Type : Run PowerShell Script
Name : ‘Step # and description’
Package: ‘Package containing the Get-TimeStamp.ps1’
Script name: Get-TimeStamp.ps1
PowerShell Execution policy : Bypass

After the Task Sequence has been completed you will be able to find the corresponding Get-TimeStamp log in the folder C:\Windows\CCM\Logs\_tasksequencename-Get-TimeStamp.log’

As the log file has been written to as comma-separated-values, you can view in a text viewer, or see the information clearly when importing into excel, through Data – From Text/CSV

Example

The Duration Split is the time difference from the previous step – Have fun playing!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: