# PSScriptPad

PSScriptPad is a tiny editor for Windows PowerShell and PowerShell 7. It requires no installation or configuration and weighs in around 6MB. It can edit, execute and debug PowerShell scripts, design Windows Forms, WPF Windows and package executables.&#x20;

## Download

You can [download PSScriptPad from our website](https://ironmansoftware.com/downloads). It is a single standalone portable .exe file.&#x20;

## PowerShell Versions

PSScriptPad allows you to select the PowerShell version. The dropdown on the top of the window can be used to select the PS version.&#x20;

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MZIeAkBrJcs-B-JTKBn%2F-MZIenTVOBoaogLEAmDa%2Fimage.png?alt=media\&token=70d06c91-4d55-47ac-9b53-001b4f764150)

### Integrated Version

The integrated version uses the PowerShell host within PSScriptPad rather than starting an external PowerShell process.&#x20;

## Editing PowerShell

PSScriptPad supports editing PowerShell scripts. It supports syntax highlighting, syntax checking, IntelliSense and code folding.&#x20;

#### Creating a New PowerShell File

Click the New File button on the toolbar to create a new file.&#x20;

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-Lz08srx0vI19UqVJEc-%2F-Lz09wGqJVxSVWC2FPdb%2Fimage.png?alt=media\&token=10ad6c84-2645-477b-a469-e1e6807bd5c5)

#### Opening a PowerShell Script

Click the Open button on the toolbar to open a script file.

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-Lz09z04jdn7ZUnLX3aj%2F-Lz0AD3VjEhkv4AXuqBT%2Fimage.png?alt=media\&token=570c77b9-3b6c-496a-9323-a97c9e165be3)

#### IntelliSense&#x20;

IntelliSense is automatically invoked. It will complete PowerShell cmdlet names, variables, paths, and parameter names. You can also press `Ctrl+Space` to manually invoke IntelliSense. As you type, the IntelliSense list will be filtered. Pressing tab will select and insert the current option.&#x20;

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-Lz09z04jdn7ZUnLX3aj%2F-Lz0AZLnkiwgqy-GF8eN%2Fimage.png?alt=media\&token=ed5297b8-4817-41c4-b5d8-aba45a644657)

#### Code Folding&#x20;

Code Folding collapses blocks of PowerShell script that you wish to hide. You can collapse blocks such as if blocks, script blocks and functions blocks. Just click the minus and plus sign to close and open blocks.&#x20;

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-Lz09z04jdn7ZUnLX3aj%2F-Lz0B18XlBlw8wiz67-W%2Fimage.png?alt=media\&token=c8c429e3-0a6f-4a00-9d14-488582d40e26)

### PSScriptAnalyzer Support

PSScriptPad will show PSScriptAnalyzer warnings if it is installed. You can customize your PSScriptAnalyzer settings by placing a configuration file in `$Env:AppData\PowerShell Pro Tools\PSScriptAnalyzerSettings.psd1`.

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-M_z02-YfJGwAzRftQIm%2F-M_z0rtvZrd-XFqdeXCt%2Fimage.png?alt=media\&token=ec046897-5167-4228-9d24-566582d8fe5d)

## Debugging&#x20;

PSScriptPad can also debug PowerShell scripts. It supports executing scripts, setting breakpoints, stepping through scripts and viewing the output of scripts in the terminal window.&#x20;

### Setting a breakpoint&#x20;

You can set breakpoints by clicking in the editor margin or by using the `F9` button to toggle a breakpoint on the selected line.&#x20;

![Set a breakpoint](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MPKYAJM1bCm2McOO4qk%2F-MPK_oXZ4KRoZz96AjnT%2Fset-breakpoint.gif?alt=media\&token=ecbddedf-4dcf-4824-b744-b00577b4b6dc)

### Running a Script

You can run a script by clicking the Run button or by pressing `F5`. It will run the currently open tab.&#x20;

![Run a script](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MPKYAJM1bCm2McOO4qk%2F-MPKa0KK7SQ5_VKJ5Ztf%2Frun-script.gif?alt=media\&token=f4c070af-c544-46c3-bf75-6942575ceef2)

### Stepping through a script

You can single step through a script using the following keys:

* `F10` - Step over
* `F11` - Step Into
* `Shift+F11` - Step Out

![Stepping in a script](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MPKYAJM1bCm2McOO4qk%2F-MPKb_mg_Y70dP_dZ1Io%2Fstepping.gif?alt=media\&token=1b557d40-45c3-474a-a224-4e033d84b721)

## Packaging Scripts

PSScriptPad can package scripts to executables using [package.psd1](https://docs.poshtools.com/powershell-pro-tools-documentation/packaging/package.psd1) files or by selecting a PS1 file and packaging with the default settings.&#x20;

### Packaging Without a Package.PSD1 file

You can select a PS1 file and click the Package button and the script will be packaged into an executable. The results of the packaging process will be shown within the console.&#x20;

![Package Script](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MPKYAJM1bCm2McOO4qk%2F-MPKgB11OR0qq_N4r6B_%2Fpackage.gif?alt=media\&token=2b4ce7d8-cedb-44ff-a8a1-b78703761a64)

### Packaging with a Package.PSD1 File

[Package.psd1](https://docs.poshtools.com/powershell-pro-tools-documentation/packaging/package.psd1) files allow you to configure all the settings for the packaging process. You can create a package.psd1 file and then when you click the Package button, it will use that file for configuration.

![Package.PSD1](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MPKgwVoAlxVCWY32Ef9%2F-MPKgzLTl2ZtIcvNfn56%2Fpackagepsd1.gif?alt=media\&token=078f4075-e565-4f6d-aef7-a268abf31661)

## Windows Form Designer

The Windows Form Designer allows you to create forms with PowerShell scripts.&#x20;

### Creating a new Form

You can create a new form by clicking the dropdown arrow next to the New button and then click New Windows Form.

![New Windows Form](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MPKYAJM1bCm2McOO4qk%2F-MPKdN2EntTmEokSBoKT%2Fnew-form.gif?alt=media\&token=ce99d3a5-0519-4e90-b8d8-2f60b8814b7d)

### Adding Controls to a Form

You can add controls to a form by expanding the toolbox pane, clicking the control you'd like to add and then clicking on the form. This action requires 2 clicks. In other words, you cannot drag and drop the control from the Toolbox onto the form.

![Adding Controls to a Form](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MPKYAJM1bCm2McOO4qk%2F-MPKde7O-Q8ji8VJnsMt%2Fadd-controls.gif?alt=media\&token=b460bb6f-663e-454a-8ee7-a87cd02c18fb)

### Setting Properties of Controls

You can set the properties of a control by selecting the control and then modifying properties in the Properties pane.&#x20;

![Set Properties of a Control](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MPKYAJM1bCm2McOO4qk%2F-MPKduqH-KGjq6Tnd-jM%2Fsetprops.gif?alt=media\&token=dd211b86-60f9-4be2-9a38-286bd6de2a6f)

### Setting Event Handlers

You can set event handlers for a control by selecting the control, clicking the lightning bolt icon in the Properties pane and then typing the name of the event handler for the event you'd like to hook up. After saving the form, you can view the code-behind file to define what happens when the event takes place.&#x20;

![Setting an Event Handler](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MPKYAJM1bCm2McOO4qk%2F-MPKeQBRxR6o7Aktp7Rk%2FsetEvents.gif?alt=media\&token=76dfe089-f2ac-4e4a-8414-26cb1769f020)

### Running a Form

You can run a form by opening the PS1 file for your form and pressing `F5` or by clicking the Run button.&#x20;

![Running a Form](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MPKYAJM1bCm2McOO4qk%2F-MPKejW2xPNb08B-H1EN%2Frun-form.gif?alt=media\&token=ac00d578-7fd6-4099-8c23-22037a9ef5d6)

## Scratch Pad

The Scratch Pad is a way of quickly testing scripts. Open the Scratch Pad by clicking the Open Scratch Pad button on the toolbar. The Scratch Pad will save automatically, and you can execute scripts immediately.&#x20;

Scratches are saved and visible in the Scratches window. Scratches contain the scratch that was executed and the output that was generated from the scratch.&#x20;

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LNFE66tpE_51uobNA70%2Fuploads%2FUQp9G2Z2X5a2izeaRdn4%2Fimage.png?alt=media\&token=5c094a6b-047a-4f1f-a53a-84999da5b69d)

## WPF Designer

The WPF designer allows you to visually create WPF forms. You can use the inline editor to adjust properties of the form and see it update in real time. You can then use the XAML in your PowerShell scripts.

### Create a WPF Form

Click the New WPF Form button to create a new WPF form. It will open the WPF designer.

![WPF Editor in PSScriptPad](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MQadw0PFj0BfmgRZSyo%2F-MQaeopLQKSdGzZMs_Rj%2Fwpf.gif?alt=media\&token=c6df970d-6b85-4031-a467-06b463929027)

### Editing the Form

You can use the inline XAML editor to adjust properties of controls and add new ones. For example, you can add a button to your form by including the following XAML.

```
<Button>Click Me</Button>
```

### Setting Control Properties

You can use the Property window to set properties of a control. To do so, select the control you'd like to modify and then set the specified property in the Property window. The designer and XAML will update after you press `Enter` .&#x20;

![Setting Properties of a Window](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MQgpQtPIHk5na4Y5aEZ%2F-MQgpr14zP6TmObZseCB%2Fproperties.gif?alt=media\&token=64475f34-3242-4e70-89b0-e3183f36cb13)

### Integrating with PowerShell

Depending on the PowerShell host, you may need to load the WPF framework.

```
[System.Reflection.Assembly]::LoadWithPartialName("PresentationFramework") | Out-Null
```

XAML can be loaded directly with PowerShell using WPF classes. To load a WPF form from XAML, you can use the `Import-Xaml` function below.

```
function Import-Xaml {
	[xml]$xaml = Get-Content -Path $PSScriptRoot\WpfWindow.xaml
	$manager = New-Object System.Xml.XmlNamespaceManager -ArgumentList $xaml.NameTable
	$manager.AddNamespace("x", "http://schemas.microsoft.com/winfx/2006/xaml");
	$xamlReader = New-Object System.Xml.XmlNodeReader $xaml
	[Windows.Markup.XamlReader]::Load($xamlReader)
}
```

To show the form, you can load the XAML, store the result in a variable and then call `ShowDialog`.

```
$Window = Import-Xaml
$Window.ShowDialog()
```

You can configure event handlers by selecting the controls and then add script blocks to the events. You will need to ensure that you have names provided for your controls. For example, the XAML below defines a button with the name `Button`.

```
<?xml version="1.0" encoding="utf-16"?>
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Name="wpfWindow" Background="White" Title="WPF Window">
   <Button x:Name="Button">Click</Button>
</Window>
```

To select the button in PowerShell, you can use the Window's `FindName` method.

```
$Button = $Window.FindName('Button')
```

To set an event handler, like a button click, you can then use `add_Click` on the button.

```
$Button.add_Click({
   # Script Here
})
```

## Options

### Context Menu

Add an Open with PSScriptPad context menu item to Windows Explorer so you can right click on PS1 files and open them in the editor.

### Font Size

Set the font size for the terminal and code editor windows.

### Override Execution Policy

Set the execution policy for PSScriptPad to Bypass.

### Themes

You can switch between dark and light themes using the options dialog.&#x20;

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MCrQByF6JNVr71Pmkn3%2F-MCrQcvZzzduxtNpxvIp%2Fimage.png?alt=media\&token=0a75887e-ee64-47da-8784-7324991bfcdd)

## Keyboard Shortcuts

| Keyboard Shortcuts | Action                      | Used In                |
| ------------------ | --------------------------- | ---------------------- |
| Ctrl+S             | Save                        | Script, Form Designers |
| F5                 | Start Debugging or Continue | Script                 |
| F8                 | Execute Selection           | Script                 |
| F9                 | Toggle Breakpoint           | Script                 |
| F10                | Step Over                   | Script                 |
| F11                | Step Into                   | Script                 |
| Shift+F11          | Step Out                    | Script                 |
| Ctrl+F             | Find                        | Script, Console        |
| F3                 | Find Next                   | Script, Console        |
| Shift+F3           | Find Previous               | Script, Console        |
| Ctrl+C             | Copy                        | Script, Console        |
| Ctrl+X             | Cut                         | Script, Console        |
| Ctrl+V             | Paste                       | Script, Console        |
| Ctrl+H             | Replace                     | Script, Console        |
| Ctrl+Z             | Undo                        | Script, Console        |
| Ctrl+Y             | Redo                        | Script, Console        |
| Ctrl++             | Zoom In                     | Script, Console        |
| Ctrl+-             | Zoom Out                    | Script, Console        |
