Branding devices using Collection Variables, Task Sequences and PowerShell

Customer asked me to figure out a way to make it easy for them to create\manage a Machine based Environment Variable en-mass, so I came up with something that uses PowerShell, Task Sequences and Collection Variables.

Save this script as SysEnvVarBranding.ps1 to a new Package Source Folder location:

# Get the Task Sequence Variables

$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment

# Set the Machine Environment Variable BrandingKey with the Collection Variable BrandingValue

[Environment]::SetEnvironmentVariable("BrandingKey", $tsenv.Value("BrandingValue"), "Machine")

 

Change the two highlighted keywords before saving your script:

BrandingKey: This is the name of the variable you will create\manage on the device

BrandingValue: This is the Collection Variable Name that you will create below

 

Now create yourself a new Collection

Create a new Collection Variable for this Collection, calling it BrandingValue (or whatever you defined it as above)

Create a new Package containing your SysEnvVarBranding.ps1 script and distribute it to your Distribution Points

Create a new Custom Task Sequence

Add a Run Command Line step using the following details:

Name: Run SYSVAR branding script

Command Line: powershell.exe -executionpolicy bypass -File SysEnvVarBranding.ps1

Include a Package: Select your newly created Package

Deploy the Task Sequence to your controlling Collection, add a device to the collection to test and you are done.

If you tell that device to get fetch new Policy you should see the deployment for this new Task Sequence appear in Software Center, launch it and monitor the SMSTS.LOG file for the result and then go check to see if the new Machine Environment Variable has been successfully created, you may need to exit any CMD prompts you already have open before you see the results.

Enjoy!