Running *.ps1 from converted *.exe

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
rubberduck
Posts: 54
Joined: Wed Oct 30, 2013 9:34 am

Running *.ps1 from converted *.exe

Post by rubberduck » Fri Mar 18, 2016 6:57 am

Product, version and build:Powershell Studio 2015 V 4.2.91
32 or 64 bit version of product:64
Operating system: Windows 8.1
32 or 64 bit OS: 64

Hello,

I try to open another Powershell Script from converted *.exe ( Powershell Script to exe)

If I am in Powershell Studio and working from the Script, I open another Script with double dot

Code: Select all

function Get-MyCredentials
{
. .\Credentials.ps1 -BackColor $BackColor # this opens my own created credential window, that I use often.



$Credenials = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $Password

Return $Credentials
}
and this works very well.
However if i convert my Powershell Application to an exe File, this does not work anymore.

How do I have to write the code in this case?

Greets and thanks in advance

User avatar
Alexander Riedel
Posts: 7023
Joined: Tue May 29, 2007 4:43 pm

Re: Running *.ps1 from converted *.exe

Post by Alexander Riedel » Fri Mar 18, 2016 10:14 am

"this does not work anymore" can be anything. Can you provide some details? Error messages? What is the nature of your application? Command line? Windows Forms?
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
rubberduck
Posts: 54
Joined: Wed Oct 30, 2013 9:34 am

Re: Running *.ps1 from converted *.exe

Post by rubberduck » Sat Mar 19, 2016 8:55 am

Hello and thanks for the reply.

The Multiform Scripts perpuse is to massive Reboot our Server at a scheduled time.


For this and for other scripts I wrote an own authentication form similar to Microsofts one, that I call whenever I need credentials.

Simple Thing, two textboxes returning username and Password.

This works fine if i call this 'credential.ps' from my scripts via < . . \credential.ps1 >.
If I convert my main Script to an exe File, the call for my credentials.ps Skript is ignored .
After that the sckript runs into a failure, cause no credentials are given.
I tried to convert to all kinds of Windows Forms ( 32,64, V2, V3, STA not STA etc)

The question is, how to call a Powershell Script from a converted executable.

If you need the full code, ist not a Problem, didnt want to bother you with 1500 Lines of code.
Greets and thanks in advance
. 2016-03-19 16.45.22.png
. 2016-03-19 16.45.22.png (4.33 KiB) Viewed 2178 times
Attachments
Massive Rebooter 2016-03-19 16.44.46.png
Massive Rebooter 2016-03-19 16.44.46.png (9.55 KiB) Viewed 2178 times

User avatar
rubberduck
Posts: 54
Joined: Wed Oct 30, 2013 9:34 am

Re: Running *.ps1 from converted *.exe

Post by rubberduck » Tue Mar 29, 2016 6:49 am

...hm no one else has the Problem.

How do you open other skripts (or other exe) from converted powershell Skript?

User avatar
rubberduck
Posts: 54
Joined: Wed Oct 30, 2013 9:34 am

[solved]Running *.ps1 from converted *.exe

Post by rubberduck » Tue Mar 29, 2016 7:42 am

ok solved it.

changed the code from < . .\Credentials.ps -BackColor $BackColor >
to

Code: Select all

function Get-MyCredentials
{
$path = $ScriptDirectory + "\Credentials.ps1"
[b]& $path -Backcolor $BackColor[/b]

$Creds = New-Object System.Management.Automation.PSCredential -ArgumentList $Username, $Password
Return $Creds
}
And now it is working, even if I have converted my Skript to an executable