In this post you find a PowerShell script that launches BGInfo and displays the media expiration date for a ConfigMgr Standalone Media.
Credits: Thank you, Michael Niehaus, for the code snippet that converted the UTC based time stamp to a date value us mere mortals can read 🙂
Update February 2, 2024: If you don't want to use BGInfo to display the expiration date, Madhu Sunke (@MadhuSunke) graciously provided an Alternate Way of showing the info via PowerShell and Windows Presentation Foundation (WPF). Thank you!
Background
When creating a standalone media in ConfigMgr, you have an option to define an expiration date. That information is available during deployment as a task sequence variable: _SMSTSMEDIAEXPIRE
The challenge with the _SMSTSMEDIAEXPIRE variable is that it's written as two values, and the real expiration date has to be calculated. For example, the _SMSTSMEDIAEXPIRE = 31116478;1695996512 values convert to July 2, 2024 which is not easy to guess by just looking at the values. Luckily, PowerShell to the rescue:
# Calculate Media Expiry Value
[int64]$p1 = ($TSEnv.Value("_SMSTSMEDIAEXPIRE") -split ";")[0]
[int64]$p2 = ($TSEnv.Value("_SMSTSMEDIAEXPIRE") -split ";")[1]
[int64]$p = ($p1 -shl 32) + $p2
$MediaExpiryDate = [DateTime]::FromFileTimeUtc($p).ToString("MM-dd-yyyy")

Configuring the Standalone Media to Display the Expiration Date
In the ConfigMgr boot process, task sequence variables are not available until the Prestart phase is run, so that's the earliest phase the expiration date value can be displayed. I prefer to use BGInfo from Sysinternals (Microsoft) to show the information, but you can use a VBScript, HTA or PowerShell window as well.
Note: When using media for deployment there are two prestart phases: One for the boot image inside the media, and one for the media itself. I prefer the boot image one since its starts earlier and is guaranteed to have task sequence variables loaded.
Here is a guide for configuring the Prestart command:
1. Download the x64 version of BGInfo and the blog post sample files to a folder.

2. Configure your boot image to use the files the files and the prestart command:
powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File .\ApplyMediaBGInfo.ps1

3. Create a standalone media as usual, and deploy a machine with it.
4. After clicking next in the initial Task Sequence Wizard page, the script will read the variable and display it on the background. See the below screenshots.


Does this work for PXE boot images? Specifically, I am looking for a way to check the expiry of a cert on an existing PXE boot image. I appreciate you can dig it out in SCCM but was wondering if there is a way to physically examine it from the image itself, preferable online but if not, offline.
Thanks
Not that I know of. I have used web services for a client-side script to look up certificates on the server side. If you are looking for free, the RestPS RESTful API is good; otherwise, commercial alternatives exist.