Share via


SMS TS Environment and getting Variable via PS

Question

Friday, April 25, 2014 2:12 PM

Hi guys and fellow sufferes :),

I am in trouble with a PS script running inside as TaskSequence ... 

A collection-variable (e.g. "Language") is given (entered by the installer) and I am trying to get the value inside a Powershell Script...

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

$NewVariable = $TSEnv.Value ("Language")

Unfortunately I am not the PS crack... only what I want to archive is to have the value of the collection variable Language in a Powershell Variable .. If I debug the TS and run a GetVariables() I do see a list of all TS Variables... including my own "Language Variable" ...

Someone any idea/hint !?

Thanks in advance !

Markus

All replies (7)

Friday, April 25, 2014 4:25 PM âś…Answered

Hmm, you could utilize the IsVM and IsLaptop task sequence variables, but then you are going to have alot of steps to try to set the OSDComputerName. PowerShell would probably be better, try something like this out. I threw it together quickly, but should be a start.

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

$isvm = $tsenv.Value('IsVm')
$islaptop = $tsenv.Value('IsLaptop')
$language = $tsenv.Value('Language')
$serial = $tsenv.Value('SerialNumber')

switch ($language) {
    English {$osdcomputername = "EN"}
    French {$osdcomputername = "FR"}
    Spanish {$osdcomputername = "SP"}
    default {$osdcomputername = "EN"}
}

if ($isvm) {
    $osdcomputername += "VM"
} elseif ($islaptop) {
    $osdcomputername += "NB"
    $osdcomputername += $serial
} else {
    $osdcomputername += "DT"
    $osdcomputername += $serial
}

$tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
$tsenv.Value('OSDComputername') = $osdcomputername

Daniel Ratliff | http://www.PotentEngineer.com


Friday, April 25, 2014 2:41 PM

Are you doing a package or run command line?

Check here for a reference: http://www.potentengineer.com/using-powershell-to-set-osd-task-sequence-variables/

Daniel Ratliff | http://www.PotentEngineer.com


Friday, April 25, 2014 2:41 PM

It is a powershell script, running in a Task Sequence and it is coming via Package of course....


Friday, April 25, 2014 2:48 PM

Can you clarify what you are wanting to do with the data in the Language variable? Write it in the smsts.log? Display it on the screen?

Daniel Ratliff | http://www.PotentEngineer.com


Friday, April 25, 2014 2:50 PM

Sure Daniel... depending on the content of the Language Variable I would like to generate a different OSDComputername... for example if the language is PL for Poland the OSDComputername should start with "Pl"+$SerialNumber ....


Friday, April 25, 2014 3:04 PM

Ah, thats a piece of cake. You don't even need PowerShell.

Add a task to set the task sequence variable for OSDComputerName. On that task set a condition referencing the Language variable. Then add other tasks for each Language variable you may have to check. The only thing you want to double check is the variable used for serial number. I only used %serialnumber% as an example.

Daniel Ratliff | http://www.PotentEngineer.com


Friday, April 25, 2014 3:18 PM

Daniel, that is pretty nice indeed... but furthermore I also need afterwards to make a difference between VMs and Workstations and Notebooks depending on the Computermodel so setting within PS would be nicer ...

For Example OSDComputername =

"EN" for English+

"NB" for Notebook+

"1234567" Serialnumber

Thanks for you help...