{"id":237,"date":"2014-12-05T11:59:00","date_gmt":"2014-12-05T11:59:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/12\/05\/powertip-create-self-updating-variable\/"},"modified":"2019-02-18T10:36:44","modified_gmt":"2019-02-18T17:36:44","slug":"powertip-create-self-updating-variable","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/powertip-create-self-updating-variable\/","title":{"rendered":"PowerTip: Create Self-Updating Variable"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Learn how to create a self-updating variable.<\/span>\n<img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Question\">&nbsp;How can I create a variable that will automatically update when I call it?<\/p>\n<p style=\"margin-left:30px\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" alt=\"Hey, Scripting Guy! Answer\">&nbsp;Use&nbsp;<b>Set-PSBreakPoint<\/b>&nbsp;to set a variable that will always have the current date and time (or only time):<\/p>\n<p style=\"margin-left:120px\">Set-PSBreakpoint -Variable Time -Mode Read -Action {$Global:Time=(Get-Date).ToShortTimeString();$Global:Time}<\/p>\n<p style=\"margin-left:120px\">$Time<\/p>\n<p style=\"margin-left:120px\">Set-PSBreakpoint -Variable Date -Mode Read -Action {$Global:Date=Get-Date;$Global:Date}<\/p>\n<p style=\"margin-left:120px\">$Date<\/p>\n<p style=\"margin-left:60px\"><b>Note<\/b>&nbsp;&nbsp;You need to call the variable to kick off the&nbsp;<b>PSBreakPoint<\/b>&nbsp;action script block the first time. <br \/>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;After that, the information will be up-to-date.<\/p>\n<p style=\"margin-left:120px\">PS C:&gt; $Date<\/p>\n<p style=\"margin-left:120px\">Wednesday, October 29, 2014 10:01:28 PM<\/p>\n<p style=\"margin-left:120px\">PS C:&gt; $Time<\/p>\n<p style=\"margin-left:120px\">10:01 PM<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to create a self-updating variable. &nbsp;How can I create a variable that will automatically update when I call it? &nbsp;Use&nbsp;Set-PSBreakPoint&nbsp;to set a variable that will always have the current date and time (or only time): Set-PSBreakpoint -Variable Time -Mode Read -Action {$Global:Time=(Get-Date).ToShortTimeString();$Global:Time} $Time Set-PSBreakpoint -Variable Date -Mode Read -Action {$Global:Date=Get-Date;$Global:Date} $Date Note&nbsp;&nbsp;You [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[162,555,356,3,556,45],"class_list":["post-237","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-boe-prox","tag-breakpoint","tag-powertip","tag-scripting-guy","tag-variable","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to create a self-updating variable. &nbsp;How can I create a variable that will automatically update when I call it? &nbsp;Use&nbsp;Set-PSBreakPoint&nbsp;to set a variable that will always have the current date and time (or only time): Set-PSBreakpoint -Variable Time -Mode Read -Action {$Global:Time=(Get-Date).ToShortTimeString();$Global:Time} $Time Set-PSBreakpoint -Variable Date -Mode Read -Action {$Global:Date=Get-Date;$Global:Date} $Date Note&nbsp;&nbsp;You [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=237"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/237\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}