How to Save a Script

Applies To: Windows PowerShell 2.0

Use the following steps to save and name a script. An asterisk appears next to the script name to mark a file that has not been saved since it was altered. The asterisk disappears when the file is saved.

To save a script

On the toolbar, click Save, or on the File menu, click Save.

To save and name a script

  1. On the File menu, click Save As. The Save As dialog box will appear.

  2. In the File name box, enter a name for the file.

  3. In the Save as type box, select a file type. For example, in the Save as type box, select “PowerShell Scripts (* .ps1)”.

  4. Click Save.

To save a script in ASCII encoding

Windows PowerShell ISE saves new script files (.ps1), script data files (.psd1), and script module files (.psm1) as Unicode (BigEndianUnicode) by default. To save a script in another encoding, such as ASCII (ANSI), use the Save or SaveAs methods on the $psISE.CurrentFile object.

The following command saves a new script as MyScript.ps1 with ASCII encoding.

$psise.CurrentFile.SaveAs("MyScript.ps1", [System.Text.Encoding]::ASCII)

The following command replaces the current script file with a file with the same name, but with ASCII encoding.

$psise.CurrentFile.Save([System.Text.Encoding]::ASCII)

The following command gets the encoding of the current file.

$psise.CurrentFile.encoding

Windows PowerShell ISE supports the following encoding options: ASCII, BigEndianUnicode, Unicode, UTF32, UTF7, UTF8 and Default. The value of the Default option varies with the system.

Windows PowerShell ISE does not change the encoding of scripts that were created by in other editors, even when you use the Save or Save As commands in Windows PowerShell ISE.

See Also

Other Resources

How to Create and Run a Script
How to Edit Text in the Script Pane
How to Manage and Close Script Tabs