Call form with other credentials

Use this forum to ask questions before you buy. Need information on licensing or pricing? Questions about a trial version? This is the right place for you. No scripting questions, please.
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.
User avatar
Lindevang
Posts: 5
Joined: Wed Jun 20, 2012 10:14 pm

Call form with other credentials

Post by Lindevang » Wed Jun 20, 2012 10:14 pm

Hi thereI'm considering purchasing PowerShell Studio 2012, but I have some issues (maybe rookie mistakes) that are holding be back.I want to use credentials stored in a variable (after get-credentials) and call another PFF form with this.Here is the function I use to collect the credentials:function Connect-AD { $user = "$env:USERNAME" $cred = Get-Credential "domain$user" $username = $cred.username $password = $cred.GetNetworkCredential().password $CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedName $domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain,$UserName,$Password) if ($domain.name -eq $null) { $richtextboxInfo.Text += "ERROR : Authentication failed - please verify your username and password and try again." } else { $richtextboxInfo.Text += "SUCCESS : Successfully authenticated with domain NCLAN. Please Wait" $buttonLogin.Enabled = $false Start-Sleep -Seconds 2 #>>>>> HERE I WANT TO CALL ANOTHER FORM WITH $CRED }Please help!

User avatar
davidc
Posts: 5888
Joined: Thu Aug 18, 2011 4:56 am

Call form with other credentials

Post by davidc » Thu Jun 21, 2012 5:57 am

If you add a parameter block at the top of the Form's script editor you can use that to pass a parameter:param ([System.Management.Automation.PSCredential]$Cred)Call the form:
Call-Test_Form2_pff -Cred $credYou can also specify a script scope variable and reference that variable from the second form:$script:cred = Get-Credential ... David
David
SAPIEN Technologies, Inc.

User avatar
Lindevang
Posts: 5
Joined: Wed Jun 20, 2012 10:14 pm

Call form with other credentials

Post by Lindevang » Thu Jun 21, 2012 11:44 pm

Thank you David. It works like a charm :)How do set the first form to exit when "Test_Form2" opens? When I set an "Exit" after Call-Test_Form2_pff i get an error.

User avatar
davidc
Posts: 5888
Joined: Thu Aug 18, 2011 4:56 am

Call form with other credentials

Post by davidc » Fri Jun 22, 2012 3:56 am

You shouldn't use the exit command when working with forms. You can close the form by using $form1.Close() method instead.For more information on how to close a form refer to the following blog articles: http://www.sapien.com/blog/2011/06/01/p ... m-control/ http://www.sapien.com/blog/2011/06/07/p ... n-control/ David
David
SAPIEN Technologies, Inc.

User avatar
Lindevang
Posts: 5
Joined: Wed Jun 20, 2012 10:14 pm

Call form with other credentials

Post by Lindevang » Sun Jun 24, 2012 9:14 pm

Thank you again David.Now the last question: When i use $form1.clolse() after call-form2_pff it will first close after closing form2. How can i close form1 when opening to form2?

User avatar
davidc
Posts: 5888
Joined: Thu Aug 18, 2011 4:56 am

Call form with other credentials

Post by davidc » Mon Jun 25, 2012 3:45 am

The first will always remain open even calling a sub form, but you can hide the first form by setting the form's Visible property to false. David
David
SAPIEN Technologies, Inc.