Opening another form with credentials from Get-Credential

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.
Locked
User avatar
DarkLite1
Posts: 101
Joined: Mon Mar 02, 2015 3:34 am

Opening another form with credentials from Get-Credential

Post by DarkLite1 » Mon Mar 20, 2017 1:38 am

I was wondering if it's possible to create a form that only asks for the user's credentials by invoking Get-Credential. When the credentials are collected in a variable it then launches another form with these credentials. So the new form is running under the credentials provided by 'Get-Credential'.

Is something like this possible? Currently we use a 'Caller.ps1' script that only launches 'Get-Credential', which we then use to call the main PowerShell ps1 script created in PowerShell Studio.

So, after some searching I think this is what we need:
If you don't know the user you are going to be using until run time, then you will want to create a bootstrapper packaged executable that will ask from the credentials and have that script run a secondary executable using those credentials.
Thank you for your help.

User avatar
jvierra
Posts: 11497
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Opening another form with credentials from Get-Credential

Post by jvierra » Mon Mar 20, 2017 1:58 am

Start-Process powershell myform.ps1 -credential $cred

User avatar
DarkLite1
Posts: 101
Joined: Mon Mar 02, 2015 3:34 am

Re: Opening another form with credentials from Get-Credential

Post by DarkLite1 » Mon Mar 20, 2017 2:06 am

Thank you jvierra. Is the 'Get-Credential' part than also in myForm.ps1? Or does this go in the Startup.pss file?

User avatar
jvierra
Posts: 11497
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Opening another form with credentials from Get-Credential

Post by jvierra » Mon Mar 20, 2017 2:08 am

The script that calls the second form contains the Get-Credential.

User avatar
DarkLite1
Posts: 101
Joined: Mon Mar 02, 2015 3:34 am

Re: Opening another form with credentials from Get-Credential

Post by DarkLite1 » Mon Mar 20, 2017 2:11 am

Maybe it's possible to have this in the Startup.pss file? Or should I create a separate login.psf form where I ask the credentials with a textbox?

I'm just trying to have it in the same project, so when exported it will be in the same ps1 file.

User avatar
jvierra
Posts: 11497
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Opening another form with credentials from Get-Credential

Post by jvierra » Mon Mar 20, 2017 2:16 am

Place it where you are gung to use it:

Start-Process powershell myform.ps1 -credential (Get-Vredential)

User avatar
DarkLite1
Posts: 101
Joined: Mon Mar 02, 2015 3:34 am

Re: Opening another form with credentials from Get-Credential

Post by DarkLite1 » Mon Mar 20, 2017 5:02 am

Every time I try to incorporate the following line in Login.psf or Startup.pss, a black PowerShell window pops-up that calls the form and can't get closed as it stays in the background. I can't even close it with Exit or anything else.

Code: Select all

Start-Process powershell myform.ps1 -credential (Get-Credential)

User avatar
DarkLite1
Posts: 101
Joined: Mon Mar 02, 2015 3:34 am

Re: Opening another form with credentials from Get-Credential

Post by DarkLite1 » Mon Mar 20, 2017 5:41 am

Nevermind, I found it

User avatar
AdamUK
Posts: 31
Joined: Fri Apr 29, 2016 9:07 am

Re: Opening another form with credentials from Get-Credential

Post by AdamUK » Wed Mar 22, 2017 9:46 am

It's not best practice but from the deploy tab you have copy to clipboard so you could design a form then when you press the button on that form paste the copied clipboard code then you can pass the variable along that way

Locked