Get-Credential - ButtonSubmit_Click

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 5 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
ServerStorage
Posts: 6
Last visit: Fri Oct 20, 2017 8:00 am

Get-Credential - ButtonSubmit_Click

Post by ServerStorage »

I have a GUI to create new AD users that is 99% complete. On form load event, I have added $cred = Get-Credential, which when I launch the PS GUI it opens the credential window.
$formNewUserCreat_Load={
#TODO: Initialize Form Controls here

#Get User Credential - Form will close if Cancelled or Closed
$cred = Get-Credential

I am using the Button_Click event to create the new user account using -Credential $Cred as below. When I click on the Submit button, it opens another Credential window, I type in the user name and password and the account is created.
New-ADUser @User -Credential $Cred

Why am I being prompted for the 2nd credential window?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-Credential - ButtonSubmit_Click

Post by jvierra »

Make the scope script level on both.

$script:cred
This topic is 8 years and 5 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