GUI save embedded ps1 file to disk

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 8 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
jimbobukii
Posts: 52
Last visit: Mon Dec 04, 2017 9:59 am

GUI save embedded ps1 file to disk

Post by jimbobukii »

Hi,
I have been looking at at a problem which I am sure someone will know the answer to,
A customer of ours has created a GUI with PS 2012, they have added a .ps1 file to the project.
I guess when they package to exe the .ps1 file will also be included?
One of the requirements is that when a button is clicked within the .exe it saves the .ps1 added to the project to the local disk - is this possible?
Reason why this is a requirement is that the PS1 file contains alot of reporting functionality which they do not want to break up or change, basically all they want to do is have a copy of the ps1 file saved locally if the button is clicked. The end user will then be able to use that PS1 file manually

I hope I have explained this correctly
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

GUI save embedded ps1 file to disk

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, jimbobukii.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI save embedded ps1 file to disk

Post by jvierra »

In a project add it as a txt file resource and open and save it as a ps1 file in the button.
User avatar
jimbobukii
Posts: 52
Last visit: Mon Dec 04, 2017 9:59 am

Re: GUI save embedded ps1 file to disk

Post by jimbobukii »

jvierra wrote:In a project add it as a txt file resource and open and save it as a ps1 file in the button.
Thank you for the response.
Would you kindly advise of the command?
User avatar
jimbobukii
Posts: 52
Last visit: Mon Dec 04, 2017 9:59 am

Re: GUI save embedded ps1 file to disk

Post by jimbobukii »

I used the following which seemed to work
$file = Get-Content .\PS1inTextFileFormat.txt
$file | Out-File c:\testout.ps1

is this correct way to do it?

Thanks in advance
User avatar
jimbobukii
Posts: 52
Last visit: Mon Dec 04, 2017 9:59 am

Re: GUI save embedded ps1 file to disk

Post by jimbobukii »

works with

Get-Content .\PS1inTextFileFormat.txt | Out-File c:\testout.ps1 -force

I guess this would be better
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI save embedded ps1 file to disk

Post by jvierra »

That would work.
User avatar
jimbobukii
Posts: 52
Last visit: Mon Dec 04, 2017 9:59 am

Re: GUI save embedded ps1 file to disk

Post by jimbobukii »

jvierra wrote:That would work.
thank you for your help
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: GUI save embedded ps1 file to disk

Post by jvierra »

You can also just store a short script internally as a strong
PowerShell Code
Double-click the code block to select all.
$ps1=@'
.... lines of script
'@

$ps1|Out-File myscript.ps1
This topic is 8 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked