PowerShell 3.0 and later
PowerShell ISE is completely scriptable and is accessible through the $psISE variable. This variable is present only within the PowerShell ISE.
To get to the script content of the currently visible script, try this:
To create a simple refactoring automation, this line would replace all instances of “testserver” with “productionserver” in the currently opened script inside the PowerShell ISE (so make sure you add a couple of instances of “testserver” to your current script:
$psise.CurrentFile.Editor.Text = $psise.CurrentFile.Editor.Text -replace 'testserver', 'ProductionServer'