# Run server-side script

{% hint style="info" %}
Applies to: DeployR 1.1
{% endhint %}

The **Run server-side script** step will run the specified script (e.g. "filename.ps1") on the DeployR server in the context of the service account.  It will receive the list of task sequence variables currently set on the client, and it can return back additional values that can be added to the task sequence environment.

<figure><img src="https://744643921-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJO9NLelA0RS8JB4i9oaQ%2Fuploads%2FYzVk19wElukyZh2qHAhO%2Fimage.png?alt=media&#x26;token=576b79df-69a5-4953-a4ac-3341a1616d65" alt=""><figcaption></figcaption></figure>

The script itself must be located in the "Scripts" folder in the configured content location.  By default, this location would be C:\ProgramData\2Pint Software\DeployR\Scripts. &#x20;

An example script named "SampleServerScript.ps1" can be found in the "Tools" folder in the installation path, e.g. C:\Program Files\2Pint Software\DeployR\Tools.  This example shows how to receive specific task sequence variables as named parameters, in this case a variable named "HardwareHash", and how extra parameters can be processed to get or act on the full list:

```ps1
param (
    # Fixed parameters can be used
    [Parameter(Mandatory=$true)]
    [string]$HardwareHash,

    # Capture all the rest
    [Parameter(ValueFromRemainingArguments = $true)]
    [string[]]$ExtraArgs
)
```

Because the task sequence variable values are passed as name-value pairs, the extra arguments need to be processed to associate the two into a hash table:

```ps1
# Convert the rest of the parameter pairs into a hash table
$ExtraParams = @{}
for ($i = 0; $i -lt $ExtraArgs.Count; $i += 2) {
    $key = $ExtraArgs[$i].TrimStart('-')  # Remove leading dash
    $value = $ExtraArgs[$i + 1]
    $ExtraParams[$key] = $value
}
```

New task sequence variables can be set by having the script return new PSCustomObject instances to the pipeline:

```ps1
# Return values ca/n be one or more custom objects with name/value pairs.  These will be set in the client's task
# sequence environment automatically.
[PSCustomObject] @{ name = "VarName"; value = "VarValue" }
[PSCustomObject] @{ name = "VarName2"; value = "VarValue2" }
```

Other types of objects should not be written to the pipeline.

The output from PowerShell-standard "Write-Information," "Write-Warning", "Write-Error" and "Write-Verbose" cmdlets will be written to the DeployR service's Logger event log.
