PowerShell: Date Picker.

Quick function to prompt a user to select a date. Usage is pretty straighforward.

1
$var = $(DatePicker "<title>").ToShortDateString()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function DatePicker($title) {
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$global:date = $null
$form = New-Object Windows.Forms.Form
$form.Size = New-Object Drawing.Size(233,190)
$form.StartPosition = "CenterScreen"
$form.KeyPreview = $true
$form.FormBorderStyle = "FixedSingle"
$form.Text = $title
$calendar = New-Object System.Windows.Forms.MonthCalendar
$calendar.ShowTodayCircle = $false
$calendar.MaxSelectionCount = 1
$form.Controls.Add($calendar)
$form.TopMost = $true
$form.add_KeyDown({
if($_.KeyCode -eq "Escape") {
$global:date = $false
$form.Close()
}
})
$calendar.add_DateSelected({
$global:date = $calendar.SelectionStart
$form.Close()
})
[void]$form.add_Shown($form.Activate())
[void]$form.ShowDialog()
return $global:date
}
Write-Host (DatePicker "Start Date")
Previous
Previous

App-V 5.0: PowerShell VE launcher.

Next
Next

Citrix: Creating Reports.