Label – used for labeling some parts of scripts’ GUI.It can be used to get the value of the PoSh script parameter RadioButton – lists some text options and allows to select only one of them.CheckBox – used to list some options and select them prior to running script.Similarly, you can create the following graphic elements on the form: What’s next? Now you can add a more complex UI element to your PowerShell form.
So, you built your first simple graphical user interface for a PowerShell script. If you select the user account and click the Check button, the form displays the time when the user’s last password was changed in Active Directory. As you can see, the drop-down list is automatically filled with the names of the user accounts from Active Directory. If you want to hide some of the GUI elements on a Windows Form, use the Visible property. $Label3.Text = ::FromFileTime((Get-ADUser -identity $lectedItem -Properties pwdLastSet).pwdLastSet).ToString('MM dd yy : hh ss') To convert the date from the TimeStamp format to the more convenient form, we use the function ::FromFileTime: $Button.Add_Click(
The following code will be executed when the user clicks on the button. Now put the button on the form: $Button = New-Object The second will show the time of the last password change for the selected user account: $Label2 = New-Object $ComboBox.Location = New-Object (60,10)Īdd two more labels to the form. $Users = get-aduser -filter * -Properties SamAccountName You can get AD user list using the Get-ADuser cmdlet (from Active Directory for Windows PowerShell module): $ComboBox = New-Object $Label.Location = New-Object (0,10)Ĭreate a drop-down list and fill it with a list of accounts from the Active Directory domain. To add various graphical dialog and control elements to it, add the code below before the last line ($main_form.ShowDialog()).Ĭreate a label element on the form: $Label = New-Object Adding Dialog-Box Components to your PowerShell FormĪs you can see, an empty form is displayed.