Reputation: 1
I created a PowerShell script that disables AD Users in Bulk, however, when the script runs the cmdlet Set-ADAccountExpiration -Identity $User -DateTime "$EndDate"
where the $EndDate comes from Windows Form code below, he sets the expiration date for the AD User account as US Format (08/03/2021 - MM/DD/YYYY) instead of 'Global' Format (03/09/2021 - DD/MM/YYYY) even when I print the $EndDate I get 'Global' Format: 01/09/2021 00:00:00
$Form = New-Object Windows.Forms.Form -Property @{
StartPosition = [Windows.Forms.FormStartPosition]::CenterScreen
Size = New-Object Drawing.Size 300, 230
Text = 'Select User Contract Date'
Topmost = $true
FormBorderStyle = 'FixedDialog'
MaximizeBox = $false
}
$Calendar = New-Object Windows.Forms.MonthCalendar -Property @{
ShowTodayCircle = $false
MaxSelectionCount = 1
}
$Form.Controls.Add($Calendar)
$OKButton = New-Object Windows.Forms.Button -Property @{
Location = New-Object Drawing.Point 95, 165
Size = New-Object Drawing.Size 75, 23
Text = 'OK'
DialogResult = [Windows.Forms.DialogResult]::OK
}
$Form.AcceptButton = $OKButton
$Form.Controls.Add($OKButton)
$Result = $Form.ShowDialog()
if ($Result -eq [Windows.Forms.DialogResult]::OK) {
$EndDate = $Calendar.SelectionStart
}
Upvotes: 0
Views: 169
Reputation: 61123
I think it would be easier for you to use a DateTimePicker object instead of the MonthCalendar
.
On a DateTimePicker, you can set the date format quite easily:
$Calendar = [System.Windows.Forms.DateTimePicker]::new()
$Calendar.Format = [System.Windows.Forms.DateTimePickerFormat]::Custom
$Calendar.CustomFormat = 'dd/MM/yyyy'
Upvotes: 1