Scripting for OSD
On this page, we'll cover how create PowerShell scripts specific to DeployR Task Sequence environment, and then how to add them to your Task Sequence.
Connecting to the Task Sequence Environment
To leverage the variables in the task sequence, or create task sequence variables with PowerShell, you'll need to add a simple line into your script:
Import-Module DeployR.Utility
Once you've done that, you can start pulling in variables you've set in the Task Sequence, or ones that are auto generated. You can access the variables by using ${TSEnv:VariableName}. Here is an example of pulling three Task Sequence variables into standard PowerShell variables to be used later in the script.
[String]$MakeAlias = ${TSEnv:MakeAlias}
[String]$ModelAlias = ${TSEnv:ModelAlias}
[int]$OSImageBuild = ${TSEnv:OSImageBuild}
if ($MakeAlias -ne "Dell" -and $MakeAlias -ne "Lenovo" -and $MakeAlias -ne "HP" -and $MakeAlias -ne "Panasonic Corporation" -and $MakeAlias -ne "Microsoft") {
Write-Host "MakeAlias must be Microsoft, Dell, Lenovo, Panasonic or HP. Exiting script."
Exit 0
}
To create Task Sequence variables that can then be used by other steps in your task sequence, once you've connected into your TS environment by using the Import-Module DeployR.Utility command, you will simply set the variable:
$tsenv:LineOfBusiness = "RetailAgents"
$tsenv:HyperVHost = (Get-ItemPropertyValue -Path 'HKLM:\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters' -Name "HostName" -ErrorAction SilentlyContinue)

For this example, I've added a step that runs those two lines, we'll take a look at the logs and variables:

Last updated