What is the difference between variables $a and $b?
$a = (Get-Date).DayOfWeek
$b = Get-Date | Select-Object DayOfWeek
I tried to check
$a.GetType
$b.GetType
MemberType : Method
OverloadDefinitions : {type GetType()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : type GetType()
Name : GetType
IsInstance : True
MemberType : Method
OverloadDefinitions : {type GetType()}
TypeNameOfValue : System.Management.Automation.PSMethod
Value : type GetType()
Name : GetType
IsInstance : True
But there seems to be no difference although the output of these variables looks different.
First of all, you lack parentheses to call GetType. What you see is the MethodInfo describing the GetType method on [DayOfWeek]. To actually call GetType, you should do:
You should see that
$ais a [DayOfWeek], and$bis a custom object generated by the Select-Object cmdlet to capture only the DayOfWeek property of a data object. Hence, it’s an object with a DayOfWeek property only: