Application of the Week – Windows Calculator (Part 2)

Application of the week > Application of the Week – Windows Calculator (Part 2)

In Last week’s blog about Windows Calculator I talked about provisioned apps in Windows 10. In this week’s blog I provide you a PowerShell script which uses our Liquit PowerShell Module to create a ‘Windows Calculator’ Launch package.

First of all you need to install both the Liquit Agent and the Liquit Workspace Powershell Module. Both can be downloaded here. The documentation for this Module can be found online here. Do follow the Liquit Release & Patch twitter feed if you like to receive updates for that module similar to this one.

The PowerShell script below lists most ‘Provisioned Windows apps’ referred to in this list. I left the Xbox ones out, for obvious reasons 😉

When you select a provisioned app, it will query for this app using the ‘Package name’. Which in this case is ‘Microsoft.WindowsCalculator’ after selecting ‘Windows Calculator’.

After selecting the app, a Launch package is created an published.

Import-Module "C:\Program Files (x86)\Liquit Workspace\PowerShell\3.0\Liquit.Server.PowerShell.dll" -Prefix "Liquit"

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

#define all Liquit related variables
$liquitZoneUsername = "local\admin"
$liquitZonePassword = Read-Host "Enter Password" -AsSecureString
$liquitCredentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $liquitZoneUsername, $liquitZonePassword
$liquitZone = "https://yourliquitzone.liquit.com"
$liquitContext = Connect-LiquitWorkspace -URI $liquitZone -Credential $liquitCredentials

#define the form parameters
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Provisioned Windows Apps'
$form.Size = New-Object System.Drawing.Size(300,675)
$form.StartPosition = 'CenterScreen'
$form.MinimumSize = New-Object System.Drawing.Size(300,675)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(120,550)
$OKButton.Size = New-Object System.Drawing.Size(75,25)
$OKButton.Text = 'OK'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$OKButton.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor 
                   [System.Windows.Forms.AnchorStyles]::Right
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(195,550)
$CancelButton.Size = New-Object System.Drawing.Size(75,25)
$CancelButton.Text = 'Cancel'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$CancelButton.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor 
                       [System.Windows.Forms.AnchorStyles]::Right
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = 'Select a Provisioned Windows app:'
$form.Controls.Add($label)

$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(260,940)
$listBox.Height = 500
$listBox.Anchor = [System.Windows.Forms.AnchorStyles]::Bottom -bor
                  [System.Windows.Forms.AnchorStyles]::Top -bor
                  [System.Windows.Forms.AnchorStyles]::Left -bor
                  [System.Windows.Forms.AnchorStyles]::Right

[void] $listBox.Items.Add('3D Builder')
[void] $listBox.Items.Add('MSN Weather')
[void] $listBox.Items.Add('App Installer')
[void] $listBox.Items.Add('Get Help')
[void] $listBox.Items.Add('Microsoft Tips')
[void] $listBox.Items.Add('HEIF Image Extensions')
[void] $listBox.Items.Add('Microsoft Messaging')
[void] $listBox.Items.Add('Mixed Reality Viewer')
[void] $listBox.Items.Add('My Office')
[void] $listBox.Items.Add('Microsoft Solitaire Collection')
[void] $listBox.Items.Add('Microsoft Sticky Notes')
[void] $listBox.Items.Add('Mixed Reality Portal')
[void] $listBox.Items.Add('Paint 3D')
[void] $listBox.Items.Add('OneNote')
[void] $listBox.Items.Add('Paid Wi-Fi & Cellular')
[void] $listBox.Items.Add('Microsoft People')
[void] $listBox.Items.Add('Print 3D')
[void] $listBox.Items.Add('Snip & Sketch')
[void] $listBox.Items.Add('Skype')
[void] $listBox.Items.Add('Store Purchase App')
[void] $listBox.Items.Add('Microsoft Pay')
[void] $listBox.Items.Add('Microsoft Photos')
[void] $listBox.Items.Add('Windows Alarms & Clock')
[void] $listBox.Items.Add('Windows Calculator')
[void] $listBox.Items.Add('Windows Camera')
[void] $listBox.Items.Add('Mail and Calendar')
[void] $listBox.Items.Add('Feedback Hub')
[void] $listBox.Items.Add('Windows Maps')
[void] $listBox.Items.Add('Windows Voice Recorder')
[void] $listBox.Items.Add('Microsoft Store')
[void] $listBox.Items.Add('Your Phone')
[void] $listBox.Items.Add('Groove Music')
[void] $listBox.Items.Add('Movies & TV')

$form.Controls.Add($listBox)
$form.Topmost = $true

#show the form
$result = $form.ShowDialog()

if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
    $packageName = $listBox.SelectedItem
           
    if ($packageName -eq "3D Builder")
    {
        $selectedAppxPackagename = "Microsoft.3DBuilder"
    }
    elseif ($packageName -eq "MSN Weather")
    {
        $selectedAppxPackagename = "Microsoft.BingWeather"
    }

    elseif ($packageName -eq "App Installer")
    {
        $selectedAppxPackagename = "Microsoft.DesktopAppInstaller"
    }

    elseif ($packageName -eq "Get Help")
    {
        $selectedAppxPackagename = "Microsoft.GetHelp"
    }

    elseif ($packageName -eq "Microsoft Messaging")
    {
        $selectedAppxPackagename = "Microsoft.Messaging"
    }

    elseif ($packageName -eq "Mixed Reality Viewer")
    {
        $selectedAppxPackagename = "Microsoft.Microsoft3DViewer"
    }

    elseif ($packageName -eq "My Office")
    {
        $selectedAppxPackagename = "Microsoft.MicrosoftOfficeHub"
    }
        
    elseif ($packageName -eq "Microsoft Solitaire Collection")
    {
        $selectedAppxPackagename = "Microsoft.MicrosoftSolitaireCollection"
    }

    elseif ($packageName -eq "Microsoft Sticky Notes")
    {
        $selectedAppxPackagename = "Microsoft.MicrosoftStickyNotes"
    }

    elseif ($packageName -eq "Paint 3D")
    {
        $selectedAppxPackagename = "Microsoft.MSPaint"
    }
    
    elseif ($packageName -eq "OneNote")
    {
        $selectedAppxPackagename = "Microsoft.Office.OneNote"
    }

    elseif ($packageName -eq "Paid Wi-Fi & Cellular")
    {
        $selectedAppxPackagename = "Microsoft.OneConnect"
    }

    elseif ($packageName -eq "Microsoft People")
    {
        $selectedAppxPackagename = "Microsoft.People"
    }
    
    elseif ($packageName -eq "Print 3D")
    {
        $selectedAppxPackagename = "Microsoft.Print3D"
    }

    elseif ($packageName -eq "Snip & Sketch")
    {
        $selectedAppxPackagename = "Microsoft.ScreenSketch"
    }

    elseif ($packageName -eq "Skype")
    {
        $selectedAppxPackagename = "Microsoft.SkypeApp"
    }
    
    elseif ($packageName -eq "Store Purchase App")
    {
        $selectedAppxPackagename = "Microsoft.StorePurchaseApp"
    }
    
    elseif ($packageName -eq "Microsoft Pay")
    {
        $selectedAppxPackagename = "Microsoft.Wallet"
    }

    elseif ($packageName -eq "Microsoft Photos")
    {
        $selectedAppxPackagename = "Microsoft.Windows.Photos"
    }

    elseif ($packageName -eq "Windows Alarms & Clock")
    {
        $selectedAppxPackagename = "Microsoft.WindowsAlarms"
    }

    elseif ($packageName -eq "Windows Calculator")
    {
        $selectedAppxPackagename = "Microsoft.WindowsCalculator"
    }

    elseif ($packageName -eq "Windows Camera")
    {
        $selectedAppxPackagename = "Microsoft.WindowsCamera"
    }

    elseif ($packageName -eq "Mail and Calendar")
    {
        $selectedAppxPackagename = "microsoft.windowscommunicationsapps"
    }

    elseif ($packageName -eq "Feedback Hub")
    {
        $selectedAppxPackagename = "Microsoft.WindowsFeedbackHub"
    }

    elseif ($packageName -eq "Windows Maps")
    {
        $selectedAppxPackagename = "Microsoft.WindowsMaps"
    }

    elseif ($packageName -eq "Windows Voice Recorder")
    {
        $selectedAppxPackagename = "Microsoft.WindowsSoundRecorder"
    }

    elseif ($packageName -eq "Microsoft Store")
    {
        $selectedAppxPackagename = "Microsoft.WindowsStore"
    }

    elseif ($packageName -eq "Your Phone")
    {
        $selectedAppxPackagename = "Microsoft.YourPhone"
    }

    elseif ($packageName -eq "Groove Music")
    {
        $selectedAppxPackagename = "Microsoft.ZuneMusic"
    }

    elseif ($packageName -eq "Movies & TV")
    {
        $selectedAppxPackagename = "Microsoft.ZuneVideo"
    }
    
    # fetch all Appx packages
    $AppxPackages = Get-AppxPackage | Where {$_.Name -match $selectedAppxPackagename}

    foreach ($AppxPackage in $AppxPackages) 
    {    
        $packageArguments = "$($AppxPackage.PackageFamilyName + "!App")"
        $packageDisplayName = ""
        $packageDescription = ""

        $package = New-LiquitPackage -Name $packageName 
                                     -Type "Launch" 
                                     -DisplayName $packageDisplayName 
                                     -Description $packageDescription 
                                     -Priority 100 -Enabled $true 
                                     -Offline $True 
                                     -Web $false 
                                     -icon $content
        $snapshot = New-LiquitPackageSnapshot -Package $package
        $filterset = New-LiquitFilterSet -Snapshot $snapshot

        #define the Launch action set
        $actionset = New-LiquitActionSet -snapshot $snapshot 
                                         -Type Launch 
                                         -name 'Launch' 
                                         -Enabled $true 
                                         -Frequency Always 
                                         -Process Sequential

        #define actions for the Launch action set
        $actionset_action = New-LiquitAction 
                            -ActionSet $actionset 
                            -Name 'Start Windows app' 
                            -Type 'processstart' 
                            -Enabled $true 
                            -IgnoreErrors $false 
                            -Settings @{name = '${SystemRoot}\explorer.exe'; parameters ='shell:Appsfolder\' + $packageArguments;} 
                            -Context User

        #move the snapshot into production
        Publish-LiquitPackageSnapshot -Snapshot $snapshot -stage Production 
    }
}

After which the Launch package is created an published.

About the author