> For the complete documentation index, see [llms.txt](https://docs.devolutions.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.devolutions.net/powershell-universal/powershell-commands/new-psuscript.md).

# New-PSUScript

## SYNOPSIS

Creates a new script within PowerShell Universal.

## SYNTAX

### ScriptBlock

```
New-PSUScript -ScriptBlock <ScriptBlock> [-ManualTime <Int32>] [-TimeOut <Double>] -Name <String>
 [-Description <String>] [-Parameter <ScriptParameter[]>] [-Tag <Tag[]>] [-Status <ScriptStatus>]
 [-Environment <String>] [-Notes <String>] [-DisableManualInvocation] [-Path <String>] [-MaxHistory <Int32>]
 [-ConcurrentJobs <Int32>] [-Credential <Variable>] [-RetryLimit <Int32>] [-DiscardPipeline] [-LoadProfile]
 [-WorkingDirectory <String>] [-Role <String[]>] [-PortalOutputType <PortalOutputType>]
 [-AvailableInBranch <String[]>] [-PortalOpenInNewWindow] [-Icon <String>]
 [-PortalBehavior <ScriptPortalBehavior>] [-PortalLeaveForm] [-DisplayOutputOnExecute]
 [-ExecutionRole <String[]>] [-ComputerName <String>] [-AppToken <String>] [-UseDefaultCredentials]
 [-Integrated] [-TrustCertificate] [-Cookies] [<CommonParameters>]
```

### Path

```
New-PSUScript [-ManualTime <Int32>] [-TimeOut <Double>] -Name <String> [-Description <String>]
 [-Parameter <ScriptParameter[]>] [-Tag <Tag[]>] [-Status <ScriptStatus>] [-Environment <String>]
 [-Notes <String>] [-DisableManualInvocation] -Path <String> [-MaxHistory <Int32>] [-ConcurrentJobs <Int32>]
 [-Credential <Variable>] [-RetryLimit <Int32>] [-DiscardPipeline] [-LoadProfile] [-WorkingDirectory <String>]
 [-Role <String[]>] [-PortalOutputType <PortalOutputType>] [-AvailableInBranch <String[]>]
 [-PortalOpenInNewWindow] [-Icon <String>] [-PortalBehavior <ScriptPortalBehavior>] [-PortalLeaveForm]
 [-DisplayOutputOnExecute] [-ExecutionRole <String[]>] [-ComputerName <String>] [-AppToken <String>]
 [-UseDefaultCredentials] [-Integrated] [-TrustCertificate] [-Cookies]
 [<CommonParameters>]
```

### Module

```
New-PSUScript [-ManualTime <Int32>] [-TimeOut <Double>] [-Description <String>]
 [-Parameter <ScriptParameter[]>] [-Tag <Tag[]>] [-Status <ScriptStatus>] [-Environment <String>]
 [-Notes <String>] [-DisableManualInvocation] [-MaxHistory <Int32>] [-ConcurrentJobs <Int32>]
 [-Credential <Variable>] [-RetryLimit <Int32>] [-DiscardPipeline] [-LoadProfile] [-WorkingDirectory <String>]
 -Module <String> -Command <String> [-Role <String[]>] [-PortalOutputType <PortalOutputType>]
 [-AvailableInBranch <String[]>] [-PortalOpenInNewWindow] [-Icon <String>]
 [-PortalBehavior <ScriptPortalBehavior>] [-PortalLeaveForm] [-DisplayOutputOnExecute]
 [-ExecutionRole <String[]>] [-ComputerName <String>] [-AppToken <String>] [-UseDefaultCredentials]
 [-Integrated] [-TrustCertificate] [-Cookies] [<CommonParameters>]
```

## DESCRIPTION

Creates a new script within PowerShell Universal. Scripts can be manually executed or scheduled inside PSU. Scripts created based on content will be written to the repository directory. Scripts created by path will be referenced by that path.

Script configurations are stored in .universal/scripts.ps1

You can also use this cmdlet to create scripts through the REST API.

## EXAMPLES

### Example 1

```
New-PSUScript -Name 'Script1.ps1' -Path 'Script1.ps1'
```

Creates a script within PSU that references a relative path of Script1.ps1 in the repository folder.

### Example 2

```
New-PSUScript -Name 'Script1.ps1' -ScriptBlock {
    "Hello, world!"
}
```

Creates a script within PSU based on the script block provided. This will create a Script1.ps1 file within the repository directory.

## PARAMETERS

### -AppToken

The AppToken that is used for calling the PowerShell Universal Management API. You can also call Connect-PSUServer before calling this cmdlet to set the AppToken for the entire session.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ComputerName

Specifies the computer name or URL that should be called when accessing the PowerShell Universal Management API. You can also use Connect-PSUServer before calling this cmdlet to set the computer name for the entire session.

```yaml
Type: String
Parameter Sets: (All)
Aliases: Uri

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Description

The description of the script.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -DisableManualInvocation

Disables manual invocation of the script. The script can only be run on a schedule.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```

### -ManualTime

The amount of time it would take to run this particular script manually.

```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -MaxHistory

The maximum job history for this script. This defaults to 100.

```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Name

The name of this script.

```yaml
Type: String
Parameter Sets: ScriptBlock, Path
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Notes

Notes to include with this script.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Parameter

Obsolete

```yaml
Type: ScriptParameter[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Path

The path to the script. This can be a relative path to the repository directory or an absolute path.

```yaml
Type: String
Parameter Sets: ScriptBlock
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

```yaml
Type: String
Parameter Sets: Path
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ScriptBlock

A script block to define for this script.

```yaml
Type: ScriptBlock
Parameter Sets: ScriptBlock
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Status

Not used.

```yaml
Type: ScriptStatus
Parameter Sets: (All)
Aliases:
Accepted values: Draft, Pending_Review, Published, Disabled

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Tag

Tags to assign to this script.

```yaml
Type: Tag[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ConcurrentJobs

The number of concurrent jobs that are allowed for this script. By default, there is no limit.

```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Environment

The environment to run this script within.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -TimeOut

The number of minutes before jobs based on this script will time out.

```yaml
Type: Double
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Credential

The user credential variable to use when executing this script.

```yaml
Type: Variable
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -UseDefaultCredentials

Use default credentials when connecting to the management API

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Integrated

Executes the command internally rather than using the Management API. Only works when running script from within PowerShell Universal.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -RetryLimit

The number of times to retry this script if it fails.

```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -DiscardPipeline

Whether to discard pipeline output rather than persist it in the database.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -LoadProfile

Loads the user profile when running this script as another user.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -WorkingDirectory

The working directory of the script.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Command

The command that defines this script.

```yaml
Type: String
Parameter Sets: Module
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Module

The module that contains the command that defines this script.

```yaml
Type: String
Parameter Sets: Module
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Role

The role that is required to execute this script.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -AvailableInBranch

When specified, this script will only be available in the specified branches.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -PortalOutputType

The type of portal output to display when running this script in the portal.

```yaml
Type: PortalOutputType
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -TrustCertificate

Whether the cmdlet should ignore certificate issues.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -PortalOpenInNewWindow

Whether to open this script in a new window when viewing it in the portal.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Icon

An icon to display in the portal.

```yaml
Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -DisplayOutputOnExecute

Displays output of the script while it is executing in the portal.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -PortalBehavior

How this script behaves in the portal.

```yaml
Type: ScriptPortalBehavior
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -PortalLeaveForm

Whether to leave the script's form after executing it in the portal.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -Cookies

Reuses and persists authentication cookies for the current PowerShell session.

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -ExecutionRole

Specifies one or more roles that can execute the resource.

```yaml
Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction. For more information, see [about\_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### None

## OUTPUTS

### System.Object

## NOTES

## RELATED LINKS

[Get-PSUScript](https://github.com/Devolutions/doc-gitbook/blob/master/powershell-universal/cmdlets/Get-PSUScript/README.md) [Remove-PSUScript](https://github.com/Devolutions/doc-gitbook/blob/master/powershell-universal/cmdlets/Remove-PSUScript/README.md) [Invoke-PSUScript](https://github.com/Devolutions/doc-gitbook/blob/master/powershell-universal/cmdlets/Invoke-PSUScript/README.md) [Set-PSUScript](https://github.com/Devolutions/doc-gitbook/blob/master/powershell-universal/cmdlets/Set-PSUScript/README.md) [Get-PSUEnvironment](https://github.com/Devolutions/doc-gitbook/blob/master/powershell-universal/cmdlets/Get-PSUEnvironment/README.md)


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.devolutions.net/powershell-universal/powershell-commands/new-psuscript.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
