Author Posts

May 8, 2018 at 5:47 am

I am a newbie at working with PowerShell GUIs and I am working on something now that has me a bit confused.

What I need help with is how to get a button component's associated action variable to see another component's?

For example, if I have a button titled "Do Something" and I have a Date Time Picker component and I want to use the date from the Date Time Picker in my "Do Something" button's variable, how would I go about this?

So, something like this:

$DoSomething_Button_Click {
[System.Windows.MessageBox]::Show("$Date_DateTimePicker",0,'Information')
}

I guess I am not able to add an image here, so I will just redirect to another post I have asking the same thing on TechNet here:
https://social.technet.microsoft.com/Forums/windowsserver/en-US/a485728d-35cd-4b9b-a5dd-e44899fb1eb3/powershell-gui-component-variables-isolated-from-one-another?forum=winserverpowershell

Thanks for your help on this, much appreciated.

May 10, 2018 at 9:45 pm

You can use $Date_DateTimePicker.Value in your message box. The Value property of DateTimePicker is a DateTime object.

MSDN: DateTimePicker.Value

At that point, you can manipulate the value like any other DateTime object in PowerShell, including outputting just the date as a string. You just need to know the format you want to use.