Hi,
The title might be a bit misleading on this one.
I am trying to build a string and output it to a variable called $Query based on what checkboxes are ticked.
Each of my checkboxes have a textbox beneath them, it's the content of each textbox that I want in my string but only if the checkbox is ticked. (I have added an event to each checkbox so that when the checkstate chnages the texbox is either visible or not visible)
e.g.
$checkbox_Subject_CheckedChanged={
if ($checkbox_Subject.Checked -eq $true)
{
$textbox_subject.Visible = $true
}else {
$textbox_subject.Visible = $false
}
}
Example format of query "{To:$To AND Subject:$Subject}"
$Search = Get-Mailbox | Search-Mailbox -SearchQuery $Query
So when I click my "build" button it will output the contents of the textboxes to a string
Because they are the checkbox and the textbox are separate, it is throwing me off...
Checkbox Validation
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Checkbox Validation
Okay yeah I've got it working ish...
Just on the back of this, how do take the date from the datetimepicker to a string?
I have set a custom format as MM/dd/yyyy but if I do $ToDate = $datetimepicker_ToDate.ToString() I get this:
System.Windows.Forms.DateTimePicker, Value: 13/06/2018 16:54:34
I just want the MM/dd/yyyy without the hh:mm:ss
Just on the back of this, how do take the date from the datetimepicker to a string?
I have set a custom format as MM/dd/yyyy but if I do $ToDate = $datetimepicker_ToDate.ToString() I get this:
System.Windows.Forms.DateTimePicker, Value: 13/06/2018 16:54:34
I just want the MM/dd/yyyy without the hh:mm:ss
Re: Checkbox Validation
Got it:
$FromDate = $datetimepicker_FromDate.Text | Get-Date -Format MM/dd/yyyy
$FromDate = $datetimepicker_FromDate.Text | Get-Date -Format MM/dd/yyyy
Re: Checkbox Validation
To use a custom for at you have to do two things. You have to set a "CustomFormat and you have to set "Format" to "Custom".
$datetimepicker_FromDate.CustomFormat = 'MM/dd/yyyy'
$datetimepicker_FromDate.Format = 'Custom'
To retrieve the date object we would do this:
$datetimepicker_FromDate.Value
To reformat the date object
$datetimepicker_FromDate.Value.ToString('dd-MM-yyyy')
$datetimepicker_FromDate.CustomFormat = 'MM/dd/yyyy'
$datetimepicker_FromDate.Format = 'Custom'
To retrieve the date object we would do this:
$datetimepicker_FromDate.Value
To reformat the date object
$datetimepicker_FromDate.Value.ToString('dd-MM-yyyy')