{"id":876,"date":"2015-01-19T05:41:04","date_gmt":"2015-01-19T05:41:04","guid":{"rendered":"https:\/\/poiseddevelopers.com\/reality-tech\/?p=876"},"modified":"2024-04-26T12:30:56","modified_gmt":"2024-04-26T12:30:56","slug":"crisply-report-on-script-duration","status":"publish","type":"post","link":"https:\/\/poiseddevelopers.com\/reality-tech\/crisply-report-on-script-duration\/","title":{"rendered":"Crisply report on script duration"},"content":{"rendered":"<p>While scripts can get written in a jiffy, it\u2019s best to make them usable and functional as a foundation for operability.<\/p>\n<p>Some scripts can take time to execute.\u00a0 As a habit, I tend to build into my scripts a crisp and clear report on script duration; both to console and to a logfile.<\/p>\n<p>Let\u2019s declare a logfile, and output the start of the script; let\u2019s capture the start time of the script run, and output it to console and logfile at the start of the script run:<\/p>\n<pre lang=\"php\">$startTime = get-date\r\nwrite-host  \"STARTING: $($startTime) Script: $($MyInvocation.MyCommand.Definition)\"\r\nAdd-Content $mylogfile \"STARTING: $($startTime) Script: $($MyInvocation.MyCommand.Definition)\"\r\n<\/pre>\n<p>At the end, let\u2019s do the same; output the duration of the script run to console and logfile:<\/p>\n<pre lang=\"php\">$endtime = Get-Date\r\nWrite-Host \"Started script at $($starttime), Ended script at $($endtime), duration of $($endtime.Subtract($starttime).minutes) minutes and $($endtime.Subtract($starttime).seconds) seconds \"\r\nAdd-Content $mylogfile \"Started Script: $($MyInvocation.MyCommand.Definition) at $($starttime), Ended script at $($endtime), duration of $($endtime.Subtract($starttime).minutes) minutes and $($endtime.Subtract($starttime).seconds) seconds \"\r\n<\/pre>\n<p>Simple as that. Reuse wherever needed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>While scripts can get written in a jiffy, it\u2019s best to make them usable and functional as a foundation for operability. Some scripts can take time to execute.\u00a0 As a habit, I tend to build into my scripts a crisp and clear report on script duration; both to console and to a logfile. Let\u2019s declare [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":879,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[26],"tags":[],"class_list":["post-876","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"_links":{"self":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/comments?post=876"}],"version-history":[{"count":7,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/876\/revisions"}],"predecessor-version":[{"id":893,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/posts\/876\/revisions\/893"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media\/879"}],"wp:attachment":[{"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/media?parent=876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/categories?post=876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/poiseddevelopers.com\/reality-tech\/wp-json\/wp\/v2\/tags?post=876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}