Pass Variables into Pre and Post Scripts
This article covers the feature to pass variables into pre and post scripts using Patch My PC.
Topics covered in this article:
Topic 1: Pass Variables into Pre and Post Scripts
Starting with the Patch My PC Publisher Preview Release 22.214.171.124 and Production Release 126.96.36.199, variables are now able to be passed into pre/post scripts defined in the Add custom pre/post scripts feature. These variables can be passed into the Pre/Post scripts by including them in the arguments list of the Pre/Post script.
With release 188.8.131.52 and 184.108.40.206 the following variables can be passed into Pre/Post Scripts defined in Patch My PC:
- Vendor Name
- The name of the Vendor as defined in Patch My PC (in Base64)
- Product Name
- The name of the Product as defined in Patch My PC (in Base64)
- The version of the application or update being installed
- The ConfigMgr PackageID
- Return Code (Post Script Only)
- The return code of the main installer process
Topic 2: Using the Product and Vendor names in Pre/Post Scripts
Patch My PC passes the Product and Vendor names to scripts in Base64 to avoid issues with escape characters and long names. Therefore to use the Product or Vendor names in post scripts, they will need to be converted back to a human readable string. The following PowerShell script gives an example of a script that can convert the Pre/Post script variables to a human readable string.
[CmdletBinding()] param ( [Parameter()] [String] $VendorName, [Parameter()] [String] $ProductName, [Parameter()] [String] $Version, [Parameter()] [String] $PackageID, [Parameter()] [String] $ReturnCode ) $Vendor = [Text.Encoding]::utf8.Getstring([convert]::FromBase64String($VendorName)) Write-Output "Vendor: $Vendor" > C:\out.txt $Product = [Text.Encoding]::utf8.Getstring([convert]::FromBase64String($ProductName)) Write-Output "Product: $Product" >> C:\out.txt Write-Output "Version: $Version" >> C:\out.txt Write-Output "Package ID: $PackageID" >> C:\out.txt Write-Output "Return Code: $ReturnCode" >> C:\out.txt