Easy access to current date and time
Votes from Connect: 56
Original Date Submitted: 4/12/2011 2:47:03 PM
Handle: Shay Levi
Site Name: PowerShell
Feedback ID: 659747
Frequency: Always Happens
Regression: Yes, this happens in all previous versions
PowerShell has an automatic variable, $pwd. One of its great usage is that its value is evaluated each time you call it and you can access its members without enclosing it in parenthesis.
I would like to suggest a new automatic variable (tied variable), $Now, that returns the current date and time each time it's called.
Having $Now as a new automatic variable in PowerShell can save us extra typing, prevent enclosing get-date in parenthesis (when we need to access its members) and even save us a variable assignment to hold the current date and time, it also can be used inline in cmdlet parameters value without having to create a $date variable first.
So instead of doing:
$date = (Get-Date).MemberName
We could simply do:
There's a post blog on the PowerShell team blog, by Ibrahim Abdul Rahim (http://blogs.msdn.com/b/powershell/archive/2009/03/26/tied-variables-in-powershell.aspx), that explains how to do it, and also an extended version by Lee Holmes (http://www.leeholmes.com/blog/2009/03/26/more-tied-variables-in-powershell)
Product Studio item created by Connect Synchronizer due to creation of feedback ID 659747 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=659747).
Internal BugId: 2900