GetType used in PowerShell, difference between variables

后端 未结 3 365
离开以前
离开以前 2021-01-30 19:22

What is the difference between variables $a and $b?

$a = (Get-Date).DayOfWeek
$b = Get-Date | Select-Object DayOfWeek

3条回答
  •  长情又很酷
    2021-01-30 19:42

    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:

    $a.GetType();
    $b.GetType();
    

    You should see that $a is a [DayOfWeek], and $b is 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:

    C:\> $b.DayOfWeek -eq $a
    True
    

提交回复
热议问题