Modern dialog with PowerShell and WPF

In this post I will show you the new version of the CustomDialogs library, that allows you to display cool dialog box, with PowerShell and WPF, to replace your od school message box.

How to get sample ?

What is CustomDialogs ?
The library I will talk about it is called SimpleDialog.
It has been created by Maurício Vielmo Schmaedeck who did a really nice job.
You can find the GitHub repo here.
You can find my first post here.

How it looks like ?
The library is composed of different kind of dialogs.
- Information
- Success 
- Warning
- Error
- Critical error
- Progress
- Input

In this step I guess you already have a ps1 and XAML files. If not you can find them in the download link.

Download SimpleDialog
1 / Download the Nuget.exe file. You can find it here.
2 / Copy the exe in a folder
3 / Open PowerShell and go to the folder containing the exe
4 / Type the below command:
5 / Go in the folder SimpleDialogs.2.0.1-alpha\lib\net45 

6 / There you can find the dll to use in your project, CustomDialogs.dll
7 / Create an assembly folder in your project
8 / Copy the CustomDialogs.dll in the assembly folder

How to integrate it ?
XAML part
1 / Copy the below lines in the Window part.
2 / See below my Window part after
3 / Add the below Resources part after the Window part.
4 / Add the DialogContainer Control below at the end of your XAML, before the </Grid>
Like on Windows 10 and MahApps, you can display your dialog depending of two theme.
- Light
- Dark

This can be manage in the resources part. In our example we have configured it to Light.
To change it to Dark just change Light with Dark, as below:
See below a dialog with Light theme:

See below a dialog with Dark theme:

PS1 part
1 / Add the below line, at the beginning of your script, to load the assembly
2 / Your dialog will be displayed after clicking on a button.

How to use it ?
As mentioned before the dialog should be displayed after clicking on a button.
In my XAML I added three buttons.
See below the GUI:

The simpleDialog is composed of different dialogs which are divised in three classes:
- MessageDialog
- InputDialog 
- ProgressDialog

To use one of them you will first need to create the class as below:
Then use the below line to display the dialog

See below dialog in action.

So far, we have seen how to create and display dialog, now let's see how to customize them in order to change the dialog category (information, sucess, warning...), message, title, color...

How to customize a Dialogs ?
You can customize easily your dialog using some attributes as below:

Change title
To change the dialog title use the Title attribute as below:
See below the dialog in action:

Change message
To change the dialog message use the Message attribute as below:
See below the dialog in action:

Change Severity
The MessageDialog class allows you to display different kind of dialog:
- Information
- Success
- Warning
- Error
- Critical

By default without using one of those category, the dialog looks like as below:
You can display a specific category easily using the MessageSeverity attribute on your dialog.
For instance to display a critical error dialog set MessageSeverity to Critical.
See below the PowerShell script in the button:
See below the dialog in action:

See below how looks like other dialogs:

Change dialog buttons
You can display one, two or three button in your dialog.
For that use the following attributes and set them to True or False
- ShowFirstButton
- ShowSecondButton
- ShowThirdButton

In the below example I display two buttons:
See below the dialog:

To get the selected button you will have to use the Add_ButtonClicked event.
In the below example my dialog contains two buttons OK and cancel.
I want to know which button has been clicked.

See below the dialog code to do that:
Change color
To change the dialog color use the Title attribute as below:
See below the dialog in action:

Display a countdown
You can display a countdown inside a button.
For that use the attribute, as below:
See below the dialog in action:

InputDialog: get the typed text
To use an Inputdialog proceed as for the MessageDialog:
- Create the InputDialog class
- Set the MessageSeverity to Critical
- Display the dialog

See below PowerShell code to do that:
See below how to get what use has typed in the input dialog:
See below the dialog in action:

Get Dialog properties, event, method
Each dialog has multiple attributes to customize it.
To list all available properties proceed as beelow:
1 / Open PowerShell ISE
2 / Type the below line depending of the dialog to use:
3 / All properties will be listed. For instance, see below properties available for a MessageDialog

To list all informations about a dialog (event, method, properties) proceed as below:
See below an overview for the MessageDialog:

Windows Sandbox Editor Update

In this post I will show you the new versin of my tool Windows Sandbox Editor (old nam Sandbox Configurattion Manager) that allows you to create and edit your Sandbox configuration files. You will be able to generate Sandbox to run different kind of files like PS1, VBS, EXE, msi.

Deploy Windows Sandbox through SCCM for standard user

In this post I will demonstrate how to enable the Windows Sandbox feature through SCCM and PowerShell and allow standard users to use it.

What is Windows Sandbox ?
Windows Sandbox is a new feature that allows you to run a virtualized environment from your Windows host computer.
You will be able for instance to execute a specific application on an isolated environment.
Windows Sandbox uses hardware virtualization to create this isolated environment.
You won't need to install a VM to use it.
Indeed it will use OS from your host computer.
You will be able to run it from the Start menu or create a WSB shortcut to run a sandbox with a specific configuration.

Enable execution for standard user
In my last post I explained how to allow standard user to run Windows Sandbox.
For that you will need to add the user to the Hype-V Admin group, below.
See below how to add the current user in this group through SCCM:

The PS1 script
The below script will be used to do the below actions:
- Check if Windows Sandbox is already installed or not
- Enable the Sandbox feature is needed
- Add the current user in the Hyper-V admin group

See below the full script.
It will be used in the SCCM application, copy it to you SCCM server for later.

Create the application
1 /  In your SCCM console, go to Software Library then Applications
2 / Click on Create Application
3 / Select Manually specify the application information

4 / Type a name and choose what you want

5 / Choose what you want, like an icon

6 / Click on the Add button

7 / Choose Script installer

8 / Type a name

9 / In the content location, browse to the folder path that contains the PS1
10 / In the Installation program, select the PS1 file

11 / Click on Add clause

12 / In the direction Rule choose File
13 / In the path field type %Windir%\System32\
14 / In the file or folder type WindowsSandbox.exe
15 / The direction rule will be as below

16 / Choose how you want to run the application

17 / In the Requirements part click on Next

18 / In the Software dependencies part, click on Next

19 / Click on Next
20 / Click on Close
21 / Click on Next
22 / Click on Next
23 / Click on Close

Create the collection
1 /  In your SCCM console, go to Assets and Compliance
2 / Do a right click on Device collections then Create device collection
3 / Type a collection name and choose a limit collection

4 / Click on Add Rule

5 / Select Direct Rule
6 / Click on Next
7 / In the Resources class use System Resource
8 / In the Attribute name choose Operating System Build
9 / In the Value part type the build version of the 1903, %18362%

10 / Click on Select All

11 / Click on Next then Close
12 / Click on Next
13 / Click on Next then Close

Deploy the Sandbox feature
1 / Go to Software Libray
2 / Do a right-click on the application
2 / Click on Deploy
3 / In the Collection part, browse to the Sandbox collection

4 / Click on Next
5 / Click on Add and select your DP

6 / Choose what you want and click on Next

7 / Click on Next

8 / Click on Next

9 / Click on Next
10 / Click on Close

Install through Software Center
1 / Open the Software Center
2 / The application appears in the Software Center

3 / Click on Install

Check installation
1 / Go to C:\Windows\Debug
2 / Open the file Install_Sandbox_Feature.log

3 / Check in the Hyper-V admin group
4 / Restart the computer
5 / Run Windows Sandbox

Add requirements
In this part we will add some requirements to the application.
1 / For that do a right-click on your application
2 / Click on Properties
3 / Go to Deployment Types
4 / Click on the appli and Edit

5 / Click on Requirements then Add

Computer should have at least 4GB of RAM 
6 / Select Total physical memory 
7 / Type the RAM to set and then OK

Operating System should be at least 1903
8 / Click on Add
9 / Select Custom then click on Create

10 / Create the custom rule as below then click on OK

11 / Select the new custom rule
12 / Type the 1903 version in the Value part: 18362