What is Zammel (XAML) and how can it help me make PowerShell GUI’s

Making a professional PowerShell GUI has just been attainable by using XAML. XAML (pronounced ZAMMEL) otherwise known as Extensible Application Markup Language. Is an XML-based language developed by Mircosoft which has the looks of HTML, but is made to build GUI based applications. XAML is used to define a user interface, but it creates instances of classes to set values. Creating XAML code can be done in two ways. Writing code by hand or visually by working inside Visual Studio. XAML is part of the WPF (Microsoft Windows Presentation Foundation).

Creating a XAML GUI requires you to understand the basics of drag and dropping by using Visual Studio. Maybe you already own Visual Studio, but the great people over at Microsoft have also provided us with a community version; Visual Studio Express. Visual Studio will help us manipulate the WPF which interns create the XAML code we need. Once you have acquired the product

You will want to start off by creating a new project.

VisualStudio1

 

Once the New Project Window appears to make sure to select WPF Application. It would also be a good time to name your project and the location you would like to store it.

 

 

Once inside the Project you will notice a screen like this. If you are used to coding in Visual Studio everything will be as usual. You will notice at the bottom in the Design Toolbox is the XAML code that will be needed for the PowerShell GUI.

 

To create a document of your choice. You simply locate the ToolBox and start dragging elements into the working WPF Application area.

 

I created this PowerShell code called Get-CPUProcess that will demonstrate the Task Manager. Wouldn’t it look cool if it was a GUI and not a TUI. With the power of XAML and WPF this was possible.

 

To make this process simple I have added the code need to create the XAML and WPF.

<Window x:Class="Get-CPUProcess"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     Title="Get-CPUProcess" Height="299" Width="626" Foreground="#FFDECDCD">
    <Window.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="Black" Offset="0"/>
            <GradientStop Color="#FF27358F" Offset="1"/>
        </LinearGradientBrush>
    </Window.Background>
    <Window.OpacityMask>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
            <GradientStop Color="Black" Offset="0"/>
            <GradientStop Color="#FF970F0F" Offset="1"/>
        </LinearGradientBrush>
    </Window.OpacityMask>
    <Grid>
        <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Height="30" Margin="241,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="140" FontSize="16"><Run Text="My "/><Run Language="nb-no" Text="First XAML GUI"/></TextBlock>
        <Button x:Name="GetProcess" Content="Get-Process" HorizontalAlignment="Left" Margin="274,52,0,0" VerticalAlignment="Top" Width="75" Foreground="White">
            <Button.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="#FFD35A4D" Offset="1"/>
                </LinearGradientBrush>
            </Button.Background>
        </Button>
        <ListView x:Name="listView" HorizontalAlignment="Left" Height="156" Margin="5,87,0,0" VerticalAlignment="Top" Width="608" FontSize="16">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" DisplayMemberBinding ="{Binding 'Name'}" Width="120"/>
                    <GridViewColumn Header="PID" DisplayMemberBinding ="{Binding 'PID'}" Width="120"/>
                    <GridViewColumn Header="CPU %" DisplayMemberBinding ="{Binding 'CPU'}" Width="120"/>
                    <GridViewColumn Header="Memory (MB)" DisplayMemberBinding ="{Binding 'Memory'}" Width="120"/>
                    <GridViewColumn Header="Disk (MB)" DisplayMemberBinding ="{Binding 'Disk'}" Width="120"/>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</Window>

 

Advertisements

Meltdown and Spectre vulnerabilities — PowerShell Script

Microsoft has released a PowerShell module that lets the average user check if the chip vulnerabilities are enabled on your system or not. Microsoft has already known about this issue since June 2017, but has only started to release the update for Windows OS. To make sure that you pass the checks, you will need to have an updated Windows OS with the January 2018 Security updates, and the BIOS/Firmware update for your PC.

I thought it would be best to provide the average computer user a quick way to test the system and therefore I have created this simple script. This script first turns Admin mode on, but that might require you to confirm the User Account Control (UAC) window. Then it will make sure ExecutionPolicy is set to RemoteSigned. After this, the script will check to see if PSRepository called PSGallery is trusted. Once all of that is done the script will run SpeculationControlSettings and give you an output like this.

You can find the script explained below or download it from my GitHub page.

The image above is full of read and False checks, but take a good look at the suggested actions. Installing/updating BIOS/Firmware and the January 2018 Security Update will fix the False readings to true. I am unable to install the BIOS without Company Admin password, but I have installed the January 2018 Security Update. You can see that image below.

 


### Checks if Administration mode is on ###
Function Test_Admin {
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}
if ((Test_Admin) -eq $false) {
if ($elevated)
{
# tried to elevate, did not work, aborting
}
else {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
}

exit
}

### Runs Meltdown_Spectre Script ###
Function Meltdown_Spectre {
Set-ExecutionPolicy RemoteSigned -Scope Currentuser
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Get-ExecutionPolicy
Install-Module -Name SpeculationControl
Import-Module SpeculationControl
Get-SpeculationControlSettings
}

Function Run {
Test_Admin
Meltdown_Spectre
}

Run