PowerShell Studio: Form Recovery
- Written by David Corrales
- Last Updated: 22 April 2016
- Created: 20 August 2012
- Hits: 2874
Over time we have had various users who needed to alter the form but lost the original psf file. These users only had an exported GUI script. Naturally they would ask us if they could recover the original form from the exported script. The only solution was to recreate the form by hand and manually paste the event scripts into the new form. Fortunately, this is no longer the case. PowerShell Studio has a Data Recovery feature to prevent this scenario from occurring again.
This article will help answer any questions you may have about the new recovery feature.
How do I enable Data Recovery?
To enable Recovery, go to Options->Designer. Under the Export section check the “Embed Recovery Data in Exported Scripts” option.
Note: This option is enabled by default.
How does the Data Recovery work?
When you enable Data Recovery and export a script, PowerShell Studio will insert a special block of data:
This block of data that contains all the relevant form data including other information such as packager settings (excluding security information). As you can see, the recovery data block is contained within a comment to prevent any modification to the script’s logic. For your convenience, the data block is contained in a collapsible region:
- If you modify this recovery comment block you will NOT be able to recover your original form.
- The data block only contains form and settings information. The rest of the user generated script / event blocks are recovered from the exported script itself. Therefore, it is very important that you do not modify the generated comments / headers within the exported script.
How do I recover the original form file (.psf)?
In order to recover the original file simply open the exported script in PowerShell Studio. If PowerShell Studio determines that the file was exported, it will prompt you to open or search for the original file.
If recovery data is present and PowerShell Studio fails to find original the file or if you pressed the “No” button, it will prompt you to reconstruct the original file:
If you click the “No” button, it will simply open the file.
If you click the “Yes” button, it will build and load the unsaved reconstructed file.
If the exported file’s headers have been removed or modified, PowerShell Studio may fail to find the user generated portions of the script.
Can I recover a .pfs file from an exported script?
Yes, you will be able to retrieve the original package script file (.pss) with its assembly references and packager settings (excluding security information).
Can I recover exported projects with this feature?
Yes, the data recovery feature also applies to projects as well. As long as all the vital information has not been altered or removed, PowerShell Studio will be able to recover the original project files from the exported script. The only difference between projects and single files is that the exported project script contains multiple recovery blocks as opposed to a single recovery block. Each recovery block pertains to a single project file.
- Again, it is important that you do not modify or remove the exported script’s comment headers / regions; otherwise the application will fail to recover your original files.
- PowerShell Studio can only recover project files that have their Build property set to “Include”. Therefore it will not be able to reconstruct files marked as “Content” or “Exclude”.
Can I recover my old files from a previously exported script?
No, this feature only works with scripts that have been exported while the Recovery Data feature was enabled.
Can I prevent others from restoring the original files?
Yes, if you wish to prevent others from recovering the original files, you can either disable the Recovery Data feature before exporting or simply remove the recovery data blocks from the exported script.