Application of the Week – LastPass (Part 2)

Application of the week > Application of the Week – LastPass (Part 2)

As promised in Application of the Week – LastPass (Part 1) here’s the PowerShell script to create a Smart Icon for LastPass.

Two comments:

Compared to the PowerShell scripts I’ve used so far, this script also uses Set-LiquitEntityFilter. Two filters are set for the first two actions. The AND operator is needed because both have to be valid for the action to run.

– Two filtersets use ‘processexsist’ which was undocumented. So this has been added to supported filters in the documentation.

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

$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"

$lastpassIconURL = "https://www.setupcommander.com/ico/lastpass.ico"
$lastpassIconPath = "c:\temp\lastpass.ico"

$webClient = New-Object System.Net.WebClient
$webClient.DownloadFile($lastpassIconURL,$lastpassIconPath)
$iconContent = New-LiquitContent -Path $lastpassIconPath 

$packageName = "LastPass"
$packageDisplayName = "LastPass"
$packageDescription = "LastPass"

$liquitContext = Connect-LiquitWorkspace -URI $liquitZone -Credential $liquitCredentials

$package = New-LiquitPackage -Name $packageName `
                             -Type "Launch" `
                             -DisplayName $packageDisplayName `
                             -Description $packageDescription `
                             -Priority 100 `
                             -Enabled $true `
                             -Offline $True `
                             -Web $false `
                             -Icon $iconContent 

#create the snapshot for this package
$snapshot = New-LiquitPackageSnapshot -Package $package

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

#
#define the first launch action
#
$actionset_action1 = New-LiquitAction -ActionSet $actionset `
                                      -Name 'Start LastApp for Applications' `
                                      -Type 'processstart' `
                                      -Enabled $true `
                                      -IgnoreErrors $false `
                                      -Settings @{name = '${ProgramFiles}\LastPass\lastapp.exe'; parameters = "";} `
                                      -Context User


#define the filter set for the first action
$filterset1 = New-LiquitFilterSet -Action $actionset_action1

#add a filter to the first action
$filter1_1 = new-LiquitFilter -FilterSet $filterset1 -type fileexists -Settings @{path = '${ProgramFiles}\LastPass\lastapp.exe';} -Value "true" 

#add a filter to the first action
$filter1_2 = new-LiquitFilter -FilterSet $filterset1 -type processexists -Settings @{name = 'lastapp';} -Value "true"

#set the operator for the entity filter to AND
Set-LiquitEntityFilter -Action $actionset_action1 -Operator Or

#
#define the second launch action
#
$actionset_action2 = New-LiquitAction -ActionSet $actionset `
                                      -Name 'Start LastPass for Windows Desktop' `
                                      -Type 'processstart' `
                                      -Enabled $true `
                                      -IgnoreErrors $false `
                                      -Settings @{name = '${ProgramFiles32}\LastPass\LastPassBroker.exe'; parameters = "";} `
                                      -Context User

#define the filter set for the second action
$filterset2 = New-LiquitFilterSet -Action $actionset_action2

#add a process exist filter to the second action
$filter2_1 = new-LiquitFilter -FilterSet $filterset2 -type processexists -Settings @{name = 'LastPassBroker';} -Value "true"

#add a fileexist filter to the second action
$filter2_2 = new-LiquitFilter -FilterSet $filterset2 -type fileexists -Settings @{path = '${ProgramFiles32}\LastPass\LastPassBroker.exe';} -Value "true"

#set the operator for the entity filter to AND
Set-LiquitEntityFilter -Action $actionset_action2 -Operator Or

#
#define the third launch action
#
$actionset_action3 = New-LiquitAction -ActionSet $actionset `
                                      -Name 'Start LastPass Microsoft Store App' `
                                      -Type 'processstart' `
                                      -Enabled $true `
                                      -IgnoreErrors $false `
                                      -Settings @{name = '${SystemRoot}\explorer.exe'; parameters = "Shell:AppsFolder\LastPass.LastPass_qq0fmhteeht3j!App";} `
                                      -Context User

#define the filter set for the third action
$filterset3 = New-LiquitFilterSet -Action $actionset_action3

#add a filter to the first action
$filter3 = new-LiquitFilter -FilterSet $filterset3 -type fileexists -Settings @{path = '${ProgramFiles}\WindowsApps\LastPass.LastPass_4.3.0.0_x64__sbg7naapqq8fj\AppxManifest.xml';} -Value "true"
                                                                       
#
#define the fourth launch action
#
$actionset_action4 = New-LiquitAction -ActionSet $actionset `
                                      -Name 'Open LastPass Website' `
                                      -Type 'openurl' `
                                      -Enabled $true `
                                      -IgnoreErrors $false `
                                      -Settings @{ url = 'https://lastpass.com'; browser = 0;} `
                                      -Context User


#publish the package
Publish-LiquitPackageSnapshot -Snapshot $snapshot -stage Production 

#set the entitlement
$identity = Get-LiquitIdentity -id "LOCAL\everyone"
New-LiquitPackageEntitlement -Package $package -Identity $identity -Publish Workspace
About the author