A button group produces a button with a drop down menu. This is also referred to a split button.
Loading buttons will display a loading icon while an event handler is running. This is useful for longer running events.
Outlined buttons are medium-emphasis buttons. They contain actions that are important, but aren’t the primary action in an app.
Contained buttons are high-emphasis, distinguished by their use of elevation and fill. They contain actions that are primary to your app.
write-host “hello world”
Now we can open PowerShell terminal and cd to the saved directory. To see the script in action we type ./test.ps1. It should print hello world.
Now onto the GUI script. This way will be using the forms module.
#Import ModulesAdd-Type -AssemblyName System.Windows.FormsAdd-Type -AssemblyName System.Drawing
Creating the form. We can adjust the size and where we want the form to open on the screen.
#Creates the form$form = New-Object System.Windows.Forms.Form$form.Text = “Input Dialog”$form.Size = ‘600, 300’$form.FormBorderStyle = “FixedDialog”$form.StartPosition = “CenterScreen”#Put objects here#Has to be below all the Objects$form.TopMost = $true$result = $form.ShowDialog()
Now we need to add some text and a button to the form to give it functionality. We will specify where the object is being placed and the size. Here is the text object:
#Creates text$label = New-Object System.Windows.Forms.Label$label.Location = ’10, 20’$label.Size = ‘280, 20’$label.Text = “Enter some text:”$form.Controls.Add($label)
So far it should look like this
#Creates input field$textBox = New-Object System.Windows.Forms.TextBox$textBox.Location = ’10, 40’$textBox.Size = ‘260, 20’$form.Controls.Add($textBox)
Here is the final code script and what we have so far.
Thank you for viewing this! Hopefully you learned something.
Время на прочтение
Настал тот момент когда необходимо уходить от всех зарубежных программ удаленного подключения, во всяком случае у нас в компании. Посмотрев отечественные аналоги мы пришли в ужас от стоимости и качества работы ПО. Поразмыслив какой функционал нам необходим для подключения 1-линии к пользователям поняли:
А значит нам будет достаточно простого powershell’a.
Для выполнения дальнейших действий необходимо установить модуль Active Directory для PowerShell
Теперь нужно выполнить действие при нажатии на кнопку $FormButton в котором мы должны будем найти активный сеанс пользователя удаленного ПК и подключиться к этому сеансу
Скрипт готов, бежим проверять
Так же можем добавить проверки:
С такими проверками полная версия скрипта будет выглядеть так
Powershell это очень хорошо, но запускать его жутко не удобно. Есть прекрасная возможность конвертировать полученный скрипт в exe файл
Buttons with event handlers
Button component for Universal Apps
Control Button Size
You can control the pixel size of a button based on pixel size by using the Style parameter
PowerShell scripts can be tedious to write and difficult to use. These easy-to-follow commands can help teams build GUIs for their PowerShell scripts to save time and effort.
Although PowerShell is a command-line environment, it is possible to create GUI-based PowerShell scripts. With examples ranging from simple to complex, GUI-based PowerShell scripts can be a great addition to any team’s PowerShell strategies.
From an IT standpoint, there are two main reasons you might choose to build a GUI for a PowerShell script. First, if you find yourself regularly using a particular PowerShell cmdlet that requires multiple parameters, you can use a GUI as an alternative to tedious typing.
GUI-based PowerShell scripts are also commonly employed when the IT department needs to create a script that someone outside of IT will use. Implementing a GUI enhances the script’s usability, making it more accessible for non-IT personnel.
How to create a PowerShell GUI
Although GUI-based PowerShell scripts are often complex, it’s relatively easy to create a simple GUI. Let’s create a simple script that displays the words “Hello World” inside a text box within a GUI.
Load required assemblies
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
Create GUI interface elements
Next, create the individual interface elements that you will use within the GUI. This might include labels (text), text boxes, combo boxes (menus), buttons or other graphical elements.
$OutputBox = New-Object System.Windows.Forms.textbox
$OutputBox.Text = “Hello World”
$OutputBox.Multiline = $False
$OutputBox.Size = New-Object System.Drawing.Size(100,100)
$OutputBox.Location = new-object System.Drawing.Size(20,80)
To define a GUI interface element, create a variable that will represent that element. In my example, the variable represents a textbox object because I call the variable $OutputBox and set it equal to New-Object System.Windows.Forms.textbox.
Define element attributes
Once you define a GUI interface element object, you must then pin various attributes to that object. These attributes might include things like the size, color, position or font the object uses.
My example is a single line text box because $OutputBox.Multiline is set to False. As such, Windows will ignore the text box height and simply make the text box as tall as it needs to be to accommodate a single line of text.
Create a form object
$Form = New-Object Windows.Forms.Form
$Form.Text = “Posey’s Example GUI”
$Form.Width = 300
$Form.Height = 200
$Form.BackColor=”LightBlue”
Here, I have created a form object and tied it to a variable named $Form. The form’s size is 300 pixels wide by 200 pixels high. I have also opted to color the form light blue and give the window the name “Posey’s Example GUI.”
Activate the form
The last step in the process is to activate and display the form. You can do so using these lines of code.

Use PowerShell GUI to create a Hyper-V virtual machine

Figure 3. The GUI creates the VM.
At a structural level, this script works very similarly to my “Hello World” example. The biggest difference is that I have defined many more GUI interface elements. All the text that appears within the GUI is controlled by label objects. There are also two text boxes for entering the VM name and virtual hard disk size. The GUI also contains a combo box used to select the memory amount and a Submit button.
When you create a button object, you generally need to associate a click action with the button as a way of telling PowerShell what to do when the button is clicked. In this case, the click action contains several lines of code that retrieve the values that have been entered into the GUI and puts those values into a normalized format.
From there, the script builds a string that mimics the command used to create the VM. You can then use the Invoke-Expression command to execute the string’s contents.
You can review the full code below.
Dig Deeper on Systems automation and orchestration
This example uses Set-UDElement to disable the button after performing an action.
Buttons with icons and label
Sometimes you might want to have icons for certain button to enhance the UX of the application as we recognize logos more easily than plain text. For example, if you have a delete button you can label it with a dustbin icon.




