Windows Application update workflow with deferral function
Many customers struggle to update applications without an end user impact. For this, I created a template Workspace ONE Workflow to show the possibilities to achieve an automated upgrade flow.
You can download the template from here:
https://developer.vmware.com/samples/8122/application-update-with-a-deferral-screen?h=Sample
Once imported, you should see the imported Workflow like this:
Make sure you add the needed application(s).
The flow is separated into two different workflows. On the left site you have just the installation of the application. This is the typical staging use case, where the device gets initially installed. Here we don’t need to have any deferral since the device getting prepared for work. In the template, the count of days is “7”, so if you really want to make sure the device was just enrolled, you need to reduce the days.
On the other site we have the production flow. End Users are already working on the device and you would rather not break anything. That’s why I created a basic deferral screen, where the end user can select to install the application now or the next time.
By default, the end user has the option to defer the Workflow four times.
Furthermore, be aware that in the current implementation, the Script just creates a file with the name “workflow.txt”. This means that you can’t use the script in two or more parallel running workflows.
You can also import the resources manually.
For the sensor:
$Event = Get-WinEvent -LogName Microsoft-Windows-DeviceManagement-Enterprise-Diagnostics-Provider/Admin | Where-Object {$_.ID -eq "72"} | select -Last 1
if($Event)
{
$currentdate = Get-Date
if($currentdate.AddDays(-7) -le $Event.TimeCreated)
{
$NewEnrollment = $true
}
else{$NewEnrollment = $false}
}
else{$NewEnrollment = $false}
return $NewEnrollment
For the deferral screen:
Add-Type -AssemblyName PresentationFramework
$DeferralPath = "C:\ProgramData\Airwatch\Deferral"
if((Test-Path "$($DeferralPath)\workflow.txt") -eq $true)
{
Get-Date -Format s | Out-File -FilePath "$($DeferralPath)\workflow.txt" -Append
}
else
{
New-Item -Path $DeferralPath -Name "workflow.txt" -ItemType File -Force
Get-Date -Format s | Out-File -FilePath "$($DeferralPath)\workflow.txt" -Append
}
[xml]$XAML = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Workflow deferral" Height="600" Width="600" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowStyle="None">
<Grid Background="#FFEEEEEE">
<TextBlock FontSize="24" HorizontalAlignment="center" TextWrapping="Wrap" Text="Hi $($env:text)" VerticalAlignment="Top" Height="80" Width="460" Margin="20,10,0,0"/>
<TextBlock FontSize="24" HorizontalAlignment="center" TextWrapping="Wrap" Text="There is a pending workflow for your device." VerticalAlignment="Top" Height="80" Width="460" Margin="20,100,0,0"/>
<TextBlock FontSize="24" HorizontalAlignment="Center" TextWrapping="Wrap" Text="During this time your work is might affected." VerticalAlignment="Top" Height="64" Width="460" Margin="20,180,0,0"/>
<TextBlock FontSize="24" HorizontalAlignment="Center" TextWrapping="Wrap" Text="You have the option to defer the workflow for 3 times. After that, the workflow will be forced to run." VerticalAlignment="Top" Height="100" Width="460" Margin="20,260,0,0"/>
<Button x:Name="StartButton" Foreground="White" Content="Start the workflow" FontWeight="Bold" HorizontalAlignment="Left" Margin="20,435,0,0" VerticalAlignment="Top" Width="232" Height="49" AutomationProperties.Name="Start" Background="#FF0F912C"/>
<Button x:Name="StopButton" Foreground="White" Content="Defer the workflow" FontWeight="Bold" HorizontalAlignment="Right" Margin="20,435,20,20" VerticalAlignment="Top" Width="232" Height="49" Background="#FFD60909"/>
</Grid>
</Window>
"@
$LineCount = (Get-Content "$($DeferralPath)\workflow.txt").count
if($LineCount -eq 4)
{
[xml]$XAML = @"
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Workflow deferral" Height="600" Width="600" WindowStartupLocation="CenterScreen" ResizeMode="NoResize" WindowStyle="None">
<Grid Background="#FFEEEEEE">
<TextBlock FontSize="24" HorizontalAlignment="center" TextWrapping="Wrap" Text="Hi $($env:text)" VerticalAlignment="Top" Height="80" Width="460" Margin="20,10,0,0"/>
<TextBlock FontSize="24" HorizontalAlignment="center" TextWrapping="Wrap" Text="There is a pending workflow for your device." VerticalAlignment="Top" Height="80" Width="460" Margin="20,100,0,0"/>
<TextBlock FontSize="24" HorizontalAlignment="Center" TextWrapping="Wrap" Text="During this time your work is might affected." VerticalAlignment="Top" Height="64" Width="460" Margin="20,180,0,0"/>
<TextBlock FontSize="24" HorizontalAlignment="Center" TextWrapping="Wrap" Text="The workflow will be started now!" VerticalAlignment="Top" Height="100" Width="460" Margin="20,260,0,0"/>
<Button x:Name="StartButton" Foreground="White" Content="Start the workflow" FontWeight="Bold" HorizontalAlignment="Center" Margin="0,435,0,0" VerticalAlignment="Top" Width="232" Height="49" AutomationProperties.Name="Start" Background="#FF0F912C"/>
</Grid>
</Window>
"@
Remove-Item -Path "$($DeferralPath)\workflow.txt" -Force
New-Item -Path $DeferralPath -Name "start.txt" -ItemType File -Force
New-Item -Path $DeferralPath -Name "installed.txt" -ItemType File -Force
Start-Sleep -Seconds 5
}
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$d=[Windows.Markup.XamlReader]::Load( $reader )
#Connect to Control
$d.FindName("StopButton").add_click({
$d.Close()
})
$d.FindName("StartButton").add_click({
if($LineCount)
{
Remove-Item -Path "$($DeferralPath)\workflow.txt" -Force
}
New-Item -Path $DeferralPath -Name "start.txt" -ItemType File -Force
Start-Sleep -Seconds 5
$d.Close()
})
$d.ShowDialog() | out-null
Please make sure to configure the script correctly:
The current solution uses a variable to show the enrollment username in the text. If you want to use it, make sure you add the Variable to the script:
For more Workspace ONE Freestyle Workflow examples, you can use the following link:
Empowering customers in client management since 2012.
Empowering customers in modern management since 2018.