ConfigMgr Current Branch Custom Task Sequence Variable for Computer Role
Problem
I needed a way to identify the type or role a machine was going to be within the PE portion of an OSD sequence. The initial thought was to read the computer name with wmi and use the like variable to control different actions within the task sequence. This would have worked but I needed to get this information within Windows PE and the computer name would typically be MININT-xxxxxx. You could call the task sequence variable _SMSTSMachineName or OSDComputerName but a task sequence variable can only be equal or not equal. The like variable is not allowed on any task sequence variable.
Resolution
I created a PowerShell script that will create a custom OSD Task Sequence Variable called OSDComputerRole. This script is set to run after the computer naming script that I created in a previous post found here. You can download the previous posts scripts and files from here. This new script is set to run after the OSDComputerName variable is set. The new script also uses the same csv file that the naming script utilized which is explained in the previous post. The OSDComputerRole allows for the computer role to be read from the csv file and then you can call the task sequence variable as a condition to the task sequence step. I hope this helps someone else in their search to do something similar. The code to the PowerShell script is below and can be downloaded from here.
$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$ComputerName = $tsenv.Value('OSDComputerName') $csv = Import-Csv .\Win10OUMap.csv -delimiter ';' foreach ($line in $csv) { IF ($computername -Match $line.NAME){ $tsenv.Value('OSDComputerRole') = $line.Role Exit } Else { $tsenv.Value('OSDComputerRole') = 'Unknown' } }
|
No comments:
Post a Comment