salvador dali the persistence of memory 1931

Salvador Dali – The persistence of memory (1931)

Have you ever needed to identify how Long a Task sequence run? wouldn’t it be great if you could measure how long a configmgr Task sequence took in order to deyploy a Windows Image?  Having that Information would be great to have stored somewhere so we could create reports based on it, and see over time if something has impacted our deployment process.

Originally, I only shared a Basic VBS + powerShell script Version. Today, I am happy to share a unique full Powershell Version, with logging, and error handeling and the flexibility to combine it with other tools such as the OSDTattooer Script.


 

Version 2.1 is out!

Get latest version now on technet

 

09/09/2015 : Updated to version 2.1
*Modified main code for better tattoo possiblities with the OSDTattooer Script.
*minor bug fixes.

06/04/2015 : Updated to version 2.0
* added new code used during the presentation at the BPUG meeting.
* Added Write to registry possiblities.


There are two ways of using this solution:

  • Old  style: VBS script to start the time recording process, and a Powershell Script to read it, and Tattoo it.
  • New Style: One unique PowershellScript to set and get the time process.

 

Setting up the task sequence :

 

Step1: Download the script, and prepare your Task Sequence:

During the first meeting of the Basel PowerShell User Group (BPUG), I have presented a full powershell version of this script that I use in order to measure the time it takes for a Task sequence to execute. I have finally found some time to upload it, and share it with you.

edit: The version 2.1 is an enhanced version that includes error handeling, logging,  better integrability with external tools such as the OSDTattooer Script and in the SMSTS.log(!)

The original mechanism really doesn’t changed  compared to the very first version I wrote in VBS (Beurk!): it creates a TS variable at the very beginning of the Configmgr Task sequence, and it reads it it out at the end of the task sequence.

If you want to Tattoo the time executed into the WMI, Registry and/or environment variables, combine it with the OSD Tattooer script. have a look at here –> OSD Tattooer script.

Follow These steps in order to measure configmgr Task sequence time using powershell:

1) Download the Manage-OSDTime script from Technet (If you liked it, please rate it !)

2)Create a package without a program containing the downloaded Manage-OSDTime.ps1 and upload it to your adequate distribution Points

3) Create the  “Start OSD Time process” at the very beggining of your Task sequence and configure it as on the Screen shot below.

3) Create the Start OSD Time Process after the HDD is partioned and formated, and configured it as the on the screen shot below.

SetOSDStartTime

The task sequence mechanism needs a place to download the package too, before he can execute it. For this reason, the Managed-OSDTime package must be set after the partioning disk part. If you don’t deploy bare metal machines (READ: if there is already a disk formated and usable) then you can set the Manage-OSDTime package as the very first step of your task sequence.

4) Create the  “End OSD Time process” at the very end of your Task sequence and configure it as on the Screen shot below.

get osdtime_end configmgr

Notice that I haven’t set it as the very last step of my configmgr Task sequence. That is simply because I Tattoo all of the Information in the next and last step using the OSD Tattooer script. Read more about it right here!

Manage-OSDTime.ps1 comes with the possibility to tattoo the information without any external artefacts. For that you can simply add the parameter “-Tattoo“. It will by default tattoo in the HKLM:\Software\OSBuildinfo\ It is possible to change the key value ‘OSBuildInfo‘ by adding the parameter –Root “YourCompanyName” for example.

Nethertheless, I would recommend to use the OSD-Tattooer script, which makes complete process more easy and expandable.

2) Check the results:

The information will be expressed in minutes in the following format: MM.SS (Which stands for Minute minute, second second).

When combined with the OSD-TattooerScript, information will be present in the following three locations

a) Registry

Registry

b) WMI

WMI

c)Environment variables

OSD Tattoo Environment variables

2) Getting Manage-OSDTime script execution information

I have written this script in a way, that you can find logging information on several different places:

a) SMST.Log general log file.

The Manage-OSDTime.ps1 script will create the status logs in the SMSTS.log file. The status messages are always prexided with

[OSDTIME] so, if you search information on the Manage-OSDTime.ps1 simply go search for [OSDTIME] in the SMSTS.log log file.

smsts

b) Manage-OSDTime.Log

The second place where you can find information, is in the script log it self. By default, the log is located in the following directory –> C:\System\Logs\Manage-OSDTime.Log

 

OSDLog

 

That’s basically it.

I would love to hear your feedback!

If you have done it another way in your organization, be part of the fun, and drop line explaining how you have done. I am really curious about it !

By | 2016-10-26T12:27:26+00:00 May 23rd, 2014|COM objects, ConfigMgr, PowerShell, Sticky|25 Comments

About the Author:

Stéphane is a dynamic and passionate Cloud and datacenter Microsoft MVP since. He is the founder of the Basel PowerShell user Group (BPUG), the co-founder of the French Speaking PowerShell UserGroup (FRPSUG), author, blogger, and received the community award "PowerShell Hero" from PowerShell.org. Stéphane has implemented microsoft infrastructure solutions in various countries of Europe and is currently working in Basel / Switzerland. Stéphane help his clients to reduce their global infrastructure costs by implementing Microsft infrastructure solutions by combining great products such as System Center, Windows Server, with heavy automation using Windows PowerShell. Stéphane loves languages, Belgium beer, French cheese and French Wine. If any of these topics are of your interest, don't hesitate to come and say hi.

25 Comments

  1. Josué October 26, 2016 at 8:02 am - Reply

    Hi,

    The Manage-OSDTIME.ps1 script seems not working in my side. In my smsts.log I can see:
    [OSDTIME]Starting Manage-OSDTime.ps1 with script version: 2.1 RunPowerShellScript 25/10/2016 16:26:14 304 (0x0130)
    OSDTIME]Could not find the Task sequence variable ‘StartTime’. Be sure that the variable has been set PRIOR this step using the -START switch RunPowerShellScript 25/10/2016 16:26:14 304 (0x0130)
    OSDTIME]End of Manage-OSDTIME.ps1 script. For more information check http://www.Powershelldistrict.com RunPowerShellScript 25/10/2016 16:26:14 304 (0x0130)

    Do you know what does it mean please?

    Thanks,

    • Stephane October 26, 2016 at 11:18 am - Reply

      Hi Josué,

      It seems to be that you forgot a step in your task sequence.
      As explained in step 3 of this article, the package should be called using the “-start” parameter right after the drive has been formatted. This step is essential, since it will create the main variable that contains the starting time. It is then read again at the end.

      Your error mention that that variable could not be found, and it also suggest what you should do 😉

      #Stephane

      • Josué October 26, 2016 at 11:41 am - Reply

        Thanks for your reply.

        The steps in my TS who call the ps script with the parameters -Start (right after the drive has been formatted) and -End already exist. It’s why I don’t understand why it doesn’t still work.

        Another idea?

        • Jamie Smith March 21, 2017 at 9:02 pm - Reply

          Make sure Powershell is enabled in your Boot image under additional options.

  2. Ben Kellermann October 3, 2016 at 9:22 pm - Reply

    Good Afternoon – I was looking for a script that did this and can’t believe I found one. Thanks! Unfortunately, it isn’t working for me. I have the steps configured exactly as noted above with the “-Start” one immediately after partitioning steps and the “-End” one in a proper place. If it makes a difference, my OSD TS was originally built using the MDT plugin. In smsts, I get error s similar to the below. The below specific lines are from where it tried to run with “-End.” Any suggestions?

    Property ‘HelpURI’ cannot be found for type ‘System.Management.Automation.CmdletBindingAttribute’.
    At C:\_SMSTaskSequence\Packages\AHS0021A\Manage-OSDTime.ps1:63 char:15
    + [CmdletBinding <<<< (
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException
    Process completed with error code 1

    Failed to run the action: Set OSD End Time.
    Incorrect function. (Error: 00000001; Source: Windows)

    I'm using the 2.1 PowerShell script, too…

    Thanks!

    • Stephane October 4, 2016 at 8:09 am - Reply

      Hi Ben,

      Hmmm, this seems like a small bug. I’ll have a look at this shortly and come back to you.

      #stephane

  3. Pontus June 9, 2016 at 6:57 am - Reply

    Thanks for your answer!

    Yes,Tried with a reboot after the partition part, and then its working again.

    But in the end, My time get like -500 or something like that.. Not real data, get like minus something. Any clues?

  4. Pontus June 7, 2016 at 2:12 pm - Reply

    Hey, We are currently Goin over to UEFI, and when im coming to SET OSD Start Time, it hangs and time out, any clues what could happend?

    Cheers pontus

    • Stephane June 7, 2016 at 2:18 pm - Reply

      Not directly linked with the uefi, but be sure that the script is called after the hdd is formated

  5. Michael McConnell April 20, 2016 at 10:44 pm - Reply

    Hello, is this VBS version of this still available? Seems that no matter how hard I try, I cannot get powershell to install in my winPE boot environment due to it always saying the package is not applicable even though all the versions match up. I’d probably have better luck using the VBS to set the start time.

    Thanks

    • Stephane April 21, 2016 at 5:45 pm - Reply

      I should still have it somewhere but i am out for travel at the moment. Ill upload it as soon as i get a chance.
      Concerning your ps issue, have you validated that you have enabled powershell in you winpe image (you can enable it through one of the tabs on the boot image)

  6. Isam February 11, 2016 at 4:26 pm - Reply

    Hello, I have done as instructed with the new 2.1 version, and everytime the TS gets to the step to Set OSD start time, the TS reboots and the system is at a state of no OS since the step to wipe and format the hard drive has already occurred. I tried moving the step in different orders but results are the same, the system reboots once your step is reached. Do you know what could cause this? Did I do something wrong?

    • Stephane February 11, 2016 at 4:30 pm - Reply

      Hi Isam,

      Have you looked into the smsts.log?
      It is is important that the hard drive is already formated and has a drive letter prior to the script. Maybe take a look into that direction.

      • Isam February 11, 2016 at 5:10 pm - Reply

        Thank you for the quick response. There is no smsts.log yet, since the system restarts. Our Task sequence has the following steps:
        Folder: Execute Task Sequence
        ->CUSTOM – Set SMSTSErrorDialog Timeout Variable
        ->Office/Computer/User Prompt
        Folder: Wipe Partitions (Corrects BitLocker Issues)
        ->Create Diskpart Commands – 1/3
        ->Create Diskpart Commands – 2/3
        ->Create Diskpart Commands – 3/3
        ->Wipe with DiskPart
        Folder: Initialization
        SubFolder: Partition if necessary
        SubFolder: Script exists and non-NTFS partitions
        ->Confirmation to Partition Disk
        ->Format and Partition Disk (UEFI)
        ->Format and Partition Disk
        SubFolder: Script does not exist or no partitions
        ->Format and Partition Disk (UEFI)
        ->Format and Partition Disk
        ->Set Variable for Format and Partition Disk
        ->Set Variable for Wizard
        ->Use Toolkit Package
        ->Check Pre-reqs
        ->Gather
        Folder: Validation
        SubFolder: Non-Replace
        ->Validate
        ->Check Bios
        Folder: State Capture
        ->UDI Wizard
        ->Copy SMS Logs
        ->Disable Bitlocker
        ->Set Status 1
        Folder: Preinstall
        SubFolder: New Computer Only
        ->Validate
        ->UDI Wizard
        SubFolder: Format Disk
        ->Format and Partition Disk (UEFI)
        ->Format and Partition Disk 6.1
        ->Format and Partition Disk 6.0
        ********* ->Set OSD Start Time *********** this is where I put your task to run the powershell script
        ->Set OSDDiskPart
        ->Pre-provision BitLocker
        ->Set Variable for Pre-provision BitLocker
        ->Use Toolkit Package
        SubFolder: Refresh Only
        ->Restart to Windows PE
        ->Use Toolkit Package
        ->Gather
        ->Set Status 1
        ->Backup
        Folder: Install
        ->Set Status 2
        ->Set Variable for Drive Letter
        ->Apply Operating System Image
        ->Use Toolkit Package
        Folder: Post Install

  7. alexandrelizarov January 18, 2016 at 2:13 pm - Reply

    Hello, Do you mind me asking,Is it possible to include script to MDT Task Sequence?

    • Stephane January 18, 2016 at 2:29 pm - Reply

      Hi, it absolutley is possible 🙂

  8. jf4x October 23, 2015 at 11:26 am - Reply

    Nice. Would this work with MDT (without ConfigMgr) too?

    • Stephane October 23, 2015 at 11:29 am - Reply

      I think it would yes, but i have nevet tested it. Please let us know how it works out. It could be a good opportunity to improve the script a bit more 🙂

  9. MJ February 24, 2015 at 10:09 pm - Reply

    Hi,

    The VBS script doesn’t work. Have the same issue as posted by MikeC. The logfile is empty. It failed to set sResult (line24). Can you help please

    • Stephane February 25, 2015 at 12:10 am - Reply

      Hi MJ. Of course i will help 🙂 can you send me your smsts.log per email plz? Also as a first step, you can try to comment the log file creation line, see how that works.

      • MJ February 25, 2015 at 12:50 am - Reply

        Hi, actually it failed on line 24. It passed correctly the creation of the log file. But as your advice, I comment the log file creation line but still have the same issue. it says incompatible format with the date : string : 2015-02-24 23:36:54Z……And then it continue the TS without any issue but without the variable correctly set. At the end the powershell script failed probably due to not having the right variable set. Thanks in advance for your help

        • Stephane February 25, 2015 at 9:46 am - Reply

          Hi MJ, I think I found your issue, drop me a line here : stephanevg at powershelldistrict.com and i will send you another version of the VBS script.
          Also, another question, what is your Culture settings? US-En?

  10. […] How to measure a SCCM task sequence execution time with PowerShell […]

  11. MikeC July 18, 2014 at 3:11 pm - Reply

    Hi
    I am trying to get this to work in our environment, but it’s not working, can you help?

    I have set a pause after the command in WinPE which sets the %OSDSTARTTIME% variable, but it is not being set (I know this by using a script which dumps all the TS variables to a text file) – so there is clearly an issue with the vbs – although it produces no error. The vbs DOES create the log file, but it is empty (also confirming the TS variable is not being set)

    I presume because of the above, the powershell script does nothing when run, the reg path is not created.

    Any ideas?

    • Stephane August 29, 2014 at 5:17 am - Reply

      Hello Mike,

      Sorry for the late response, you comment got a bit ofuscated by the spams..

      Even though my answer is a bit late, what do you exactly have in you log file ?

      Is it completly empty, or do you have something similar to this below ?
      The value of the sStarttime from env(OSDSTARTTIME) is :
      The value of the sEnd is :

Leave a Reply

%d bloggers like this: