I discovered something beautiful and wonderous today. It's possible in Powershell to use a variable directly as a property name! For instance:
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.
PS C:\> $d = Get-Date
PS C:\>
PS C:\> $prop = "DayOfWeek"
PS C:\>
PS C:\> $d.$prop
Thursday
PS C:\>
Copyright (C) 2012 Microsoft Corporation. All rights reserved.
PS C:\> $d = Get-Date
PS C:\>
PS C:\> $prop = "DayOfWeek"
PS C:\>
PS C:\> $d.$prop
Thursday
PS C:\>
Mind blown.
0 comments:
Post a Comment