The ISEFile Object

An ISEFile object represents a file in Windows PowerShell Integrated Scripting Environment (ISE). It is an instance of the Microsoft.PowerShell.Host.ISE.ISEFile class. This topic lists its member methods and member properties. The $psISE.CurrentFile and the files in the Files collection in a Powershell tab are instances of the Microsoft.PowerShell.Host.ISE.ISEFile class.

Methods

Save(System.Text.Encoding saveEncoding)

Saves the file to disk.

saveEncoding
Encoding to be used for the saved file.
Exceptions
  • System.IO.IOException: The file could not be saved.

# Save the file as ASCII.
$myfile=$psIse.CurrentFile
$myfile.Save( [System.Text.Encoding]::ASCII)

# Gets the current encoding.
$myfile=$psIse.CurrentFile
$myfile.Encoding

Save()

Saves the file.

Exceptions
  • System.IO.IOException: The file could not be saved.

# Explicitly save the file. 
$psIse.CurrentFile.save()

SaveAs(string fileName)

Saves the file with the specified fileName.

fileName
The name to save the file as. The default encoding for the method is UTF-16.
Exceptions
  • System.ArgumentNullException: The fileName is null.

  • System.ArgumentException: The fileName is empty.

  • System.IO.IOException: The file could not be saved.

# Explicitly save the file. 
$fullpath = "c:\temp\newname.txt"
$myfile=$psIse.CurrentFile
$myfile.SaveAs($fullPath)

SaveAs(string fileName, System.Text.Encoding saveEncoding)

Saves the file with the specified filename in the specified encoding.

fileName:
The name to save the file as. You can specify the full path name for the file.
saveEncoding
Encoding to save the file with.
Exceptions
  • System.ArgumentNullException: The fileName is null.

  • System.ArgumentException: The fileName is empty.

  • System.IO.IOException: The file could not be saved.

# Explicitly save the file as UTF8.
$fullpath = "c:\temp\newname.txt"
$myfile=$psIse.CurrentFile
$myfile.SaveAs($fullPath, [System.Text.Encoding]::UTF8)
# Gets the current encoding.
$myfile=$psIse.CurrentFile
$myfile.Encoding

Properties

DisplayName

Read-only property that gets the string that contains the display name of this file.

# Shows the display name of the file.
$psIse.CurrentFile.DisplayName

Editor

Read-only property that gets the editor that is used for the specified file.

# Gets the editor and the text.
$myfile=$psIse.CurrentFile
$myfile.Editor.Text 

Encoding

Read-only property that gets the original file encoding. This is a System.Text.Encoding object.

# Shows the encoding for the file. 
$myfile=$psIse.CurrentFile
$myfile.Encoding

FullPath

Read-only property that gets the string that specifies the full path of the opened file.

# Shows the full path for the file. 
$myfile=$psIse.CurrentFile
$myfile.FullPath

IsSaved

Read-only Boolean property that returns true if the file has been saved since it was last modified.

# Determines whether the file has been saved since it was last modified.
$myfile=$psIse.CurrentFile
$myfile.IsSaved

IsUntitled

Read-only property that is true if the file has never been given a title.

# Determines whether the file has never been given a title.
$psISE.CurrentFile.IsUntitled
$psISE.CurrentFile.SaveAs("temp.txt")
$psISE.CurrentFile.IsUntitled

See Also