Skip to content

Advanced Start

Raymond Piller edited this page Jan 25, 2023 · 2 revisions

As PSRedstone evolves, backward compatibility will be prioritized, but you should be diligent about covering your assets. I'm using the same tool, and I have the same goals in mind. However, you are responsible for ensuring your deployments remain working through code improvements and changes. While I believe in always moving forward, I believe that needs to be balanced with "if it ain't broke, don't touch it."

The only way for you to be sure that your install scripts will not break as PSRedstone updates is to lock in the version of the module that you tested during package development. Luckily, the #Requires statement has this capability built right in. Here's how you would set up a Redstone Block defining the tested version of PSRedstone.

#region Redstone Block
#Requires -Modules @{ModuleName = 'PSRedstone'; RequiredVersion = '2023.1.4.62137'}
$redstone, $settings = New-Redstone
#endregion Redstone Block

That's great, but there are a few questions left to be answered:

How do I ensure all versions of PSRedstone that I need are pre-loaded on a brand-new system?

You are responsible for ensuring your deployments remain working despite PSRedstone code improvements and changes. While I believe in always moving forward, I believe that needs to be balanced with "if it ain't broke, don't touch it." You need to track the versions of PSRedstone that are being used in your scripts, and you need to ensure those versions are available on your managed systems.

Don't worry, I'm not going to throw this burden on you without providing you with the solution that I've implemented ...

How do I prevent version bloat and remove old PSRedstone versions that are no longer needed?

Clean up the versions of PSRedstone that are installed on the system and not being used. The only way to do this is to track the versions that are being used and get rid of versions that are no longer being used.

Don't worry, I'm not going to throw this burden on you without providing you with the solution that I've implemented ...

Automated Usage and Cleanup

Don't worry, I'm not going to throw those burdens on you without providing you with the solution that I've implemented. My solution may not work for you, but it should give you an idea about how you can solve this in your environment.

TL;DR

Use the Remediation script during system setup to install all applicable versions of PSRedstone. Continue using it to ensure updates occur and cleanup of unused versions occur automatically.

Anytime this Module is used, the version and timestamp will be stored in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\VertigoRay\PSRedstone\VersionsUsed. This will allow you to know what versions are still being used so that you can intelligently purge any unused versions. Of course, a brand-new computer will not have older versions of PSRedstone installed. The easiest way around this (for now) would be to just install all versions of PSRedstone during imaging and let the script purge things after they have proven to not be in use.

I use a MECM configuration item to solve this, but you can use any method you have to deploy a script to your systems. Take a look at the provided Remediation.ps1, which will do the following:

On first run, this script will install every version of PSRedstone from the minimum version required (see parameter $MinimumVersionRequired) to the latest version. It will timestamp each version in the registry with the current date at midnight (e.g.: 2023-01-08T00:00:00.0000000). This should stand out to you as a version that was likely installed and never actually used.

PSRedstone will also update the timestamp of it's current version each time the module is imported. This makes it very easy to tell what versions are active on the system. The second parameter ($DaysAfterUnusedVersionAreUninstalled) helps us decide when to uninstall unused versions.

On the second run and all subsequent runs, this script will update to the lastest version of PSRedstone, if needed. It will also go through all versions that are currently installed and purge any versions from the system that have not been used.

Of course, every good remediation needs detection. Take a look at the provided Detection.ps1 to see how I'm doing it.

Clone this wiki locally