Display Media Expiration Date for ConfigMgr Standalone Media during OSD

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 an expiration date when creating the standalone media.

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.

The content of the package, in my lab I have them on a DFS share.

2. Configure your boot image to use the files the files and the prestart command:

powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File .\ApplyMediaBGInfo.ps1
Configuring the boot image to use a Prestart command and add the needed files.

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.

About the author

Johan Arwidmark

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

>