System.DayOfWeek是Enum
[System.DayOfWeek]

IsPublic IsSerial  Name           BaseType
--------   --------   ----               --------
True      True     DayOfWeek   System.Enum

 

我們可由以下方式列出所有DayofWeek的值有哪些
[enum]::getnames(
[System.DayOfWeek])
可列出
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday


以下可列出名稱還有相對應的值
[enum]::getnames([System.DayOfWeek]) |foreach{"Name:$_"+" Value:"+ [int][System.DayOfWeek]::$_}
可列出
Name:Sunday Value:0
Name:Monday Value:1
Name:Tuesday Value:2
Name:Wednesday Value:3
Name:Thursday Value:4
Name:Friday Value:5
Name:Saturday Value:6

創作者介紹

PowerShell@HungYuWu

ayowu 發表在 痞客邦 PIXNET 留言(1) 人氣()


留言列表 (1)

發表留言
  • 
/\/\o\/\/
wrote:
  • Some alternatives using getValues to simplify :
     
    [enum]::getvalues([System.DayOfWeek]) |foreach{"Name:$_ Value:"+ [int]$_}
    or
    [enum]::getvalues([System.DayOfWeek]) |foreach{"Name:$_ Value:"+ $_.value__}
     
    Or the way I like most make objects using select for PoSH formatting :
     
    [enum]::getvalues([System.DayOfWeek]) |select @{n='Name';e={$_}},@{n='Value';e={[int]$_}}
     
    Enjoy,
    Greetings /\/\o\/\/
找更多相關文章與討論