OSD Tattooer Script
Latest version = 1.4.3
Project is now available on Github
In order to report a Bug, or to request a new feature, please open an issue here
OSD Tattooer Script
Are you a deployment engineer, ore are you using deployment tools such as ConfigMgr / Ansible / Altiris etc.. to deploy your Windows machines? Or are you creating golden images using tools such as MDT / Packer? and are you searching for an automated, standard and reliable way to tattoo important information into your windows registry / environment variable or WMI registry of your Windows image? Then this blog post is exactly what you are looking for!
It is a common practice to tattoo the Windows Image during OSD to have global information of your image into your final build machine. This helps to identify information such as different versions of your golden image, what is the patching state, which tool was used to deploy the OS, when did it got installed? who initiated the process? how long the installation task ran? etc.. Actually, only your imagination will limit your tattooing needs here.
In this blog post I explain how to use a script I wrote called New-OSDTattoo . It is an open sourced script which allows to write data that matters to you onto your os during it’s provisioning process.
Originally I wrote this script to be used on a Microsoft SCCM environment, but I have written it in a way, that it is deployment tool agnostic. This means that you can use in other tools such as Ansible, MDT, Altiris, custom scripts etc… (Not tested).
I will demonstrate in this post how we can tattoo the following places very easily using Powershell:
- Registry
- Environment variables
- WMI repository
As a side note I have tested this script on Configmgr 2012 but it should also work on ConfigMgr 2007 as well as on other deployment tools such as MDT / Ansible / Altiris etc.. (Not tested).. Let me know how it work for you by commenting in the comment section below!
How to OSD tattoo your Windows image?
Note from stéphane of the future: This blog article was written quite some time back. I was primarily working with SCCM (The old name for Microsoft Endpoint manager 😉 ).
But this process can be used on any type of OSD deployment systems, even the custom build ones. It is basically just a script that you need to run once you have access to the OSD. You can control what needs to be written by writing environment variables with a specific naming convention.
The process is pretty straight forward, simply follow the next 3 steps and that should do the trick 🙂
1)Download the script:
First things first, you will need the New-OSDTatoo.PS1 script. You can download it here under. (and also rate it by clicking on the yellow stars ;)).
- Option A
Use the powershell gallery by using
1 |
install-script New-OSDTattoo -repository PsGallery |
If you use packer, you can use the command above to add it in your packer process.
- Option B
Clone the github repository from this location https://github.com/Stephanevg/New-Tattoo
From here on, most of the steps are very SCCM Focused. What you need to keep in mind, is that the base principle of this script, is that it will write any variable that respects a precise naming convention to a specific location that you define via parameters on the script. The below examples explain how this will work on a sccm task sequence (Endpoint Manager), but the concepts can apply to any OSD deployment technology.
2)Create a Package:
Create a SCCM package without a program with the New-OSDTattoo.ps1 script, and upload it to your desired distribution points.
As mentionned before, this is for SCCM
3)Create a PowerShell step in the task sequence:
Create a powershell execution script at the end of your task sequence and and add your package to it.
And add the package to the task and call it as follow:
In the example above, we are tattooing the variables only into the registry.
And that’s it! Simple isn’t it? (See the example below to fine tune things a bit more for your environment).
How to Tattoo OSD information using PowerShell?
In order to be able to specify a Registry root and/or a WMI class name, you will have to call the script the fallowing way.
The example above will tattoo the OSD information using the switch “All” in the root named “BPUG“.The “All” switch will tattoo the information in the following locations:
- Registry (HKLM:\Software\<ValueOfroot>)
- HKLM:\Software\BPUG
- WMI Repositroy (RootCimv2\<ValueOfRoot>)
- Root\Cimv2\BPUG
- Environment variables (Root has no influence here).
The Root switch is available since verison 1.1.0 of OSDTattooer script. Be sure to have downloaded the latest one.
Download the New-OSDTattoo.ps1 script here –> TechnetFrom the powershell gallery
How to osd tattoo the registry during SCCM OSD deployment?
In order to tattoo the registry, we will use the New-OSDTattoo.ps1 script I wrote that you can download here.
If you use the script New-OSDTattoo.ps1 it will be a peace of cake!
Simply add a PowerShell Script step in your Task sequence and call the script as followed:
1
|
New-OSDTatoo.ps1 -Registry
|
This would be the an example of the result you would get:
How to osd tattoo the WMI repository during SCCM OSD deployment?
Again, If you use the the script New-OSDTatoo.ps1 , it will be a peace of cake!
Simply add a PowerShell Script step in your Task sequence and call the script as followed:
1
|
New-OSDTattoo.ps1 -WMI
|
This would be an example of the results you could get:
I used some functions from the WMI-Module I wrote some time back for this section. Here under you will find a bit more information on WMI in general and WMI related information.
If you have no understanding of WMI and are curious to learn the basics from scratch, I recommend you take a look at this WMI introduction presentation I have done for the Bengalore PowerShell usergroup. The link is right here –> PSBUG WMI introduction
Also, have a look at the WMI week articles I wrote. They they could be handy if you need to use powershell + wmi –> WMI Week.
If you are interested in WMI, you can take a look and see how I did here –> WMI-Commands.psm1
How to osd tattoo Windows environment variables during SCCM OSD deployment?
If you want to set environment variables in SCCM during OSD deployment, use the script New-OSDTatoo.ps1 I wrote , it will be a peace of cake!
Simply add the tattoo script step in your Task sequence and call the script as followed:
1
|
New-OSDTattoo.ps1 -EnvironmentVariable
|
This could be an example that you could have:
Of course, you could have added the -Root “YourPrefix” switch. It would have then named the main class / registry hyve “YourPrefix“. (You can change this value to anything that suites you own needs, like your company name for instance). In this case, it was left to the default, which starts with psdistrict_ and which works just fine 🙂
As a side note, if the -Root switch is not specified, the default value name of the hyve / WMI class will be OsBuildInfo (So your tattooed information will be in HKLM:softwareOsBuildInfo if you do not specify any value for Root).
Script details:
The script is pretty easy to understand actually, and there is not much to be changed in it in order to be adapted to your own (or client(s)) environment.
By default, I set the following information in the tatoo mechanism:
1
2
3
4
5
6
7
|
$PSDistrict_TSName = $tsenv.Value(“_SMSTSPackageName”)
$PSDistrict_BootImageVersion = $tsenv.Value(“_SMSTSBootImageID”)
$PSDistrict_DeploymentID = $tsenv.Value(“_SMSTSLogPath”)
$PSDistrict_InstallationMethod = $tsenv.Value(“_SMSTSMediaType”)
$PSDistrict_TSID = $tsenv.Value(“_SMSTSPackageID”)
$PSDistrict_SiteCode = $tsenv.Value(“_SMSTSSiteCode”)
<del>$PSDistrict_Buildversion = $tsenv.Value(“OsBuildVersion”)</del>
|
So this tattoos the TaskSequence installation name, Boot image version, DeploymentID, Installation Method, TaskSequence Installation ID, the SCCM Site code that it is assigned to, and the current build version.
As you can see, almost all of these variables are read only variables. (See the following post on more information on Task Sequence variables –> Task sequence variables )
Each of the variables start with a prefix which is oringinaly set to $PSDistrict_ as you can see from line 592 to 598.
You can add any other OSD default variable to this list, easily by adding a new line respecting the prefix.
How to add a custom osd variable to a Windows Image?
This became actually very easy with the New-OSDTatoo.ps1 script. If you have an custom HTA in your task sequence (<– Again very SCCM / Endpoint Manager Focused 😉 ).
You can set different variables that will later on then be read by your Task sequence in order to do conditional actions, you can use the script in order to tattoo these custom variables as well.
Indeed, the important point here, is that they respect the prefix naming convention, which in the original case of this script is PSDistrict. In other words the, if you create a variable in your HTA that you would like to be tatooed into your Windows Image, all you need to do is to add a prefix to your variable. Easy isn’t? still not clear? let’s go through it together with an example.
Example:
This example might make it more clear. Let’s say you have a custom variable call “InstalledBy” that you would like to be tatooed into your registry so you can track which technician has deployed a PC.
Let’s say that this variable is already existing, and you just want to tatoo it in your registry, either change the variable name like follow: PSDistrict_InstalledBy
or, copy the old InstalledBy variable into a new variable called PSDistrict_InstalledBy and that’s it. The script will add all the variables that have a prefix of PSDistrict_ as a tatoo value. This makes it very easy to add new tatoos in your image because you will only need to worry about the new variables you will add during your task sequence, and the ones that are prefixed correctly, will automatically be written to either the registry, WMI repository, as environment variable, or simply all of them.
Ending note:
If you have used this script on another tool than SCCM, I would LOVE to hear from you (!!). Either write a comment here, or get in touch with me on the github project page of the script by opening an issue here
The script is open sourced, and can be found here -> https://github.com/Stephanevg/New-Tattoo/
If you want to report a bug, or suggest a new feature or even write an improvement your self, let’s have a chat about it here!
1 |
Write-Host "See you in the next article :)" |
[…] Osd tattoo windows image –> Link […]