> 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/automation-and-powershell/scripting-for-osd.md).

# Scripting for OSD

### Connecting to the Task Sequence Environment

To access task sequence variables or create new ones with PowerShell, add the following line to your script:

```powershell
Import-Module DeployR.Utility
```

You can then retrieve variables that you have set in the task sequence, as well as automatically generated variables, using `${TSEnv:VariableName}`. The following example assigns three task sequence variables to standard PowerShell variables for later use 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 other steps can use, import `DeployR.Utility` and then set the variables as shown below:

```
$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/8m0VARX9oyZ2zXWCdPgr/blobs/GzEoh0PESLoZNHUyQFyC/image.png" alt=""><figcaption></figcaption></figure>

For this example, I have added a step that runs those two lines. Here are the logs and variables:

<figure><img src="https://content.gitbook.com/content/8m0VARX9oyZ2zXWCdPgr/blobs/IGKmykkteMic7zLeft9n/image.png" alt=""><figcaption></figcaption></figure>

### Other DeployR.Utility commands for task sequence scripts

These commands are also useful in scripts running in a task sequence (all except `Set-DeployRLogPath` are new in DeployR 1.4):

* `Show-DeployRMessageBox`: shows a message box in the progress UI and returns the button that was clicked.
* `Set-DeployRProgressWindow`: minimizes the progress UI while your script shows its own window, then restores it.
* `Set-DeployRLogPath`: moves the DeployR logs to another folder.
* `Request-DeployRCustomContent -Hash`: downloads a file from a URL and verifies its SHA256 hash.
* `Get-DeployRDiskSectorSize`: returns the sector size of a disk.

See [DeployR.Utility module reference](/deployr/automation-and-powershell/deployr-utility-module-reference.md) for details and examples.


---

# 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/automation-and-powershell/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.
