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.

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 7 years and 6 days 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
DarkLite1
Posts: 102
Last visit: Wed Jan 06, 2021 4:12 am

Opening another form with credentials from Get-Credential

Post by DarkLite1 »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Opening another form with credentials from Get-Credential

Post by jvierra »

Start-Process powershell myform.ps1 -credential $cred
User avatar
DarkLite1
Posts: 102
Last visit: Wed Jan 06, 2021 4:12 am

Re: Opening another form with credentials from Get-Credential

Post by DarkLite1 »

Thank you jvierra. Is the 'Get-Credential' part than also in myForm.ps1? Or does this go in the Startup.pss file?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Opening another form with credentials from Get-Credential

Post by jvierra »

The script that calls the second form contains the Get-Credential.
User avatar
DarkLite1
Posts: 102
Last visit: Wed Jan 06, 2021 4:12 am

Re: Opening another form with credentials from Get-Credential

Post by DarkLite1 »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Opening another form with credentials from Get-Credential

Post by jvierra »

Place it where you are gung to use it:

Start-Process powershell myform.ps1 -credential (Get-Vredential)
User avatar
DarkLite1
Posts: 102
Last visit: Wed Jan 06, 2021 4:12 am

Re: Opening another form with credentials from Get-Credential

Post by DarkLite1 »

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.
  1. Start-Process powershell myform.ps1 -credential (Get-Credential)
User avatar
DarkLite1
Posts: 102
Last visit: Wed Jan 06, 2021 4:12 am

Re: Opening another form with credentials from Get-Credential

Post by DarkLite1 »

Nevermind, I found it
User avatar
AdamUK
Posts: 31
Last visit: Fri Jun 22, 2018 2:29 am

Re: Opening another form with credentials from Get-Credential

Post by AdamUK »

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
This topic is 7 years and 6 days 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