locked
Calculate elapsed time with VBS/PowerShell RRS feed

  • Question

  • I'm trying to calculate MDT task sequence execution time. What could be the best method for this? It can be PowerShell or VBS code.

    Plan is to execute a script at the beginning of a task sequence that stores a start time in variable and at the end of task sequence execute another script that reads that start time from variable and calculates total time taken and saves it to another variable.

    I have tried few VB scripts but I have had some odd results some times with them. We are using 24 hour clock and it might have caused some problems for my previous scripts.

     


    • Edited by jqx12 Sunday, March 22, 2015 3:27 PM
    • Moved by Bill_Stewart Monday, March 23, 2015 2:26 PM Move to more appropriate forum
    Sunday, March 22, 2015 3:26 PM

All replies

  • The MDT log already does this.  Post questions bout MDT in the deployment forum.  They will help you learn how to  use the tools.


    ¯\_(ツ)_/¯

    • Proposed as answer by jrv Friday, March 27, 2015 2:18 PM
    Sunday, March 22, 2015 4:58 PM
  • I think you can enable monitoring and then validate from a console the elapsed time.  It's a slow morning so I also wrote something that would work in powershell for fun -

    param($start, $stop)
    
    $file = $(get-date -f mmddyyyy) + '_timer.log'
    $filepath = "$env:temp\$file"
    
    
    function Start-Time {
    
        if(test-path $filepath){
        Remove-Item -path $filepath -force
        }
        
        else{
        New-Item -ItemType File -Path $filepath
        }
    
    }
    
    function Calculate-Time {
    
        if(!(Test-Path $filepath)){
    
        Write-Error "Calculate-Time: ERROR - Timer file was not found at path $filepath.  Please validate you are running this script with the -start parameter before running with the -finish parameter."
        
        }
    
        else{
            
            $fileinfo = gci $filepath
            $stime = $fileinfo.CreationTime
            $etime = (Get-Date)
    
            $time = New-TimeSpan -start $stime -end $etime
    
            return "Time from creation of file to finish is $time."
    
    
            }
    
    }
    
    
    
    function Main{
    
        if($start){
        
        Start-Time | Out-Null
        
        }
        
        if($stop){
    
        Calculate-Time | Out-Null
    
        }
        
        else{
        
        return "Main: You must provide a parameter to use this tool.  Parameters are -start to start the timer or -stop to end the timer and calculate time elapsed."
        
        }
        
            
    }
    
    Main
    

    You can modify filepath at the top to set where it saves the file.  What it does is creates a file in the environment temp directory and then uses that file creation time against current date/time to give you a duration.  Parameter -start creates the file starting the timer and parameter -stop finds that file and calculates the difference in time between creation and current time.  Either way I needed to get some powershell practice and maybe this will help you. 

    Ryan

    Wednesday, March 25, 2015 3:10 PM
  • Friday, March 27, 2015 6:14 AM
  • What I'm trying with this is to add a task sequence start time and task sequence total time to my custom report where I save information from all of the deployments run. 

    First I had a vbs script that was run at the beginning of the task sequence that just get's current time and saves it to variable. At the end of the task sequence I run another script that get's current time again and calculates elapsed time using that original "start time" variable. This didnt work because in WinPE the clock is not in sync and my start time variable shows wrong time.



    • Edited by jqx12 Monday, March 30, 2015 5:16 PM
    Monday, March 30, 2015 5:14 PM