Script method for Software Package Pre-Install Test and Conditions
When working with software packages, you have the choice of using pre-existing options vs a custom script
When creating or modifying a Software Package, the Pre-Install Test determines if the package needs to be installed or is already deployed.
You have several conditions you can choose to utilize, e.g. Registry, File, Device, and PackageCheck, as well a Script option which you can customize to your needs:
You have the option to use VBS or Powershell-based scripts
Please ensure that your script outputs $true or $false as the result, so that it can be validated by the package
In my example shown below, the decision to proceed to run the Package is if the result of my script is $false:
Example: Checking version of a specific Microsoft Store app
For Microsoft Store apps, instead of checking for a certain folder and EXE version, it's preferred to us the special System.Version Powershell variable which allows Powershell to assess the format of software version numbering x.x.x.x (major.minor.build.revision), and queries with Get-AppXPackage similar to below.
The example below is specifically checking for presence of the MicrosoftStickyNotes Store app, and if it's absent or less than 6.1.4.0, then it returns $false. Then you would set the [Script Check] expression to decide to install the package with [Script Check] == false
[System.Version]$compareVersion = "6.1.4.0"
$package = Get-AppxPackage | Where-Object {$_.Name -match "MicrosoftStickyNotes"}
if ($null -eq $package -or $null -eq $package.Version) {
$true
} elseif ($package.Version -lt $compareVersion) {
$true
} else {
$false
}
Example: Checking to see if a certain certificate is present
Powershell can be used for many functions including detecting certificates. For this example, it was used for a software package to deploy an example Personal certificate.
For specific info on deploying per-user certificates with a package, please refer to our certificate deployment KB article
(Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object { $_.Thumbprint -eq "921B97842F23474D8961BFD54911C298316AA558"}) -ne $null