> For the complete documentation index, see [llms.txt](https://documentation.2pintsoftware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.2pintsoftware.com/deployr/1.2/powershell-modules/scripting-for-osd.md).

# 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:

```powershell
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.

```powershell
[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)
```

<figure><img src="https://content.gitbook.com/content/ur9yOUrYi6pb5j4W4O2R/blobs/xdg3pEvUQHOyPxP6HcOc/image.png" alt=""><figcaption></figcaption></figure>

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

<figure><img src="https://content.gitbook.com/content/ur9yOUrYi6pb5j4W4O2R/blobs/KgqhBV8DCugpPU8WnKBy/image.png" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://documentation.2pintsoftware.com/deployr/1.2/powershell-modules/scripting-for-osd.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
