elapsed_time

Snippet Name: elapsed_time

Tags: PowerShell

Created Date: 2020-06-09 15:29:04
Last Modified Date: 2020-06-09 15:29:04

— elapsed_time

Dependencies:

DBA Notes:

Sample Output:

$TimeStart = Get-Date

^###################################################################################################
^## Logging time per thread
^###################################################################################################
$BasePath ="\\GADCDBBCK\cifs_sql_pd_backups\Releases\Documentation\DBADailyTasks\PowerShellResults\"
if(![System.IO.Directory]::Exists($BasePath)){[System.IO.Directory]::CreateDirectory($BasePath)}
$ResultsPath = [System.IO.Path]::Combine($BasePath,"PowerShellGenericLog.txt")
$elapsedTime = $(get-date) - $TimeStart
  $sb = [System.Text.StringBuilder]::new()
  $sb.Append("AdUsersV4.97.ps1") | Out-Null;$sb.Append("|") | Out-Null;
  $sb.Append($Domain) | Out-Null;$sb.Append("|") | Out-Null;
  $sb.Append($SQLServer) | Out-Null;$sb.Append("|") | Out-Null;
  $sb.Append($SQLDBName) | Out-Null;$sb.Append("|") | Out-Null;
  $sb.Append("completed in $elapsedTime at  $(get-date) ") | Out-Null;$sb.Append("") | Out-Null;
  Out-File -LiteralPath $ResultsPath -InputObject $sb.ToString() -Append -Encoding ASCII -Width 99999

Leave a Reply