PowerShellでDateTimePickerを使う

PowerShellでフォームを表示して日付と時刻を選択するサンプル。
Add-Type -AssemblyName System.Windows.Forms

$Form = New-Object System.Windows.Forms.Form
$Form.Size = "500,300"
$Form.StartPosition = "CenterScreen"
$Form.Text = "DateTimePicker"

$DatePicker = New-Object System.Windows.Forms.DatetimePicker
$DatePicker.Location = "30,20"
$DatePicker.Format = [Windows.Forms.DateTimePickerFormat]::Custom
$DatePicker.CustomFormat = "yyyy/MM/dd"
$Form.Controls.Add($DatePicker)

$TimePicker = New-Object System.Windows.Forms.DateTimePicker
$TimePicker.Location = "30,100"
$TimePicker.Format = [Windows.Forms.DateTimePickerFormat]::Custom
$TimePicker.CustomFormat = "HH:mm:ss"
$TimePicker.ShowUpDown = $TRUE
$Form.Controls.Add($TimePicker)

[void] $Form.ShowDialog()

Echo $DatePicker.Text
Echo $TimePicker.Text
powershell_datetime
実行するとこんな感じ。
    この記事で書かれている製品やソフトについて
  • Windows10 Pro 64ビット
  • PowerShell 5.1.14393.206