locked
PowerShell Credential RRS feed

  • Question

  • Hi Techies,

    I have created a form with powershell and when in the form when i enter credentails, it prompts a credential wizard and ask for login credential, which i dont want. 

    i want to execute the credentials which i enter in the form, please suggest. 

    regards

    Vinay

    Monday, March 25, 2019 2:41 PM

Answers

  • $LoginPwd = ConvertTo-SecureString -String $PwdTB.Text -AsPlainText -Force
    $credential = New-Object System.Management.Automation.PSCredential($LoginIdTB.Text, $LoginPwd)
    Connect-NcController $ClusterTB.Text -Credential $credential

    A textbox is a variable.  In a form it does not need to be saved - just reference it.

    \_(ツ)_/

    • Proposed as answer by Proed Tuesday, March 26, 2019 5:58 AM
    • Marked as answer by Vinay K Singh Wednesday, March 27, 2019 3:41 AM
    Monday, March 25, 2019 5:14 PM

All replies

  • Can you provide the code?

    There is a parameter called -UseDefaultCredential which uses the logged in user credentials. I personally have a service account logged into my server and use this parameter at the end of some of  my VMware cmdlets.


    • Edited by ktitchard Monday, March 25, 2019 2:45 PM
    Monday, March 25, 2019 2:44 PM
  • $password = "mypassword" | ConvertTo-SecureString -AsPlainText -Force
    $username = 'nwtraders\administrator'
    $credential = New-Object System.Management.Automation.PSCredential($username,$password)


    \_(ツ)_/

    Monday, March 25, 2019 2:56 PM
  • Hi please find the below

    $CredEnter.Add_Click( 
        {
           
           $loginId = $LoginIdTB.text
           $passwd =  $PwdTB.text  
     
           $credential = New-Object System.Management.Automation.PSCredential $loginId,$passwd
     
           Connect-NcController $Controller -Credential $credential
         
        })

    Monday, March 25, 2019 3:06 PM
  • Credentials require a secure password.

    \_(ツ)_/

    Monday, March 25, 2019 3:23 PM
  • agree with you, however initially i want when i enter the credential in the form i created it should execute from the form, but its prompting another credential wizard to enter the credentials.

    Monday, March 25, 2019 3:26 PM
  • agree with you, however initially i want when i enter the credential in the form i created it should execute from the form, but its prompting another credential wizard to enter the credentials.

    There is no reason for this.  If the credential parameter is null or contains invalid data then to will do that.  Run the command at a prompt to understand how it works.


    \_(ツ)_/

    Monday, March 25, 2019 4:01 PM
  • please help me to understand, how to store the forms Textbox data into a variable. 

    Example: below is a text box created, I want to store the value entered into the text box to a variable. when i execute, it doesnt show any value.

     $Controller = $ClusterTB.Text

    Please help me to understand this area

    $ClusterTB                       = New-Object system.Windows.Forms.TextBox
    $ClusterTB.multiline             = $false
    $ClusterTB.width                 = 172
    $ClusterTB.height                = 20
    $ClusterTB.location              = New-Object System.Drawing.Point(164,27)
    $ClusterTB.Font                  = 'Microsoft Sans Serif,10'

    $CredEnter                       = New-Object system.Windows.Forms.Button
    $CredEnter.text                  = "Enter"
    $CredEnter.width                 = 60
    $CredEnter.height                = 30
    $CredEnter.location              = New-Object System.Drawing.Point(192,129)
    $CredEnter.Font                  = 'Microsoft Sans Serif,10'
    $CredEnter.Add_Click( 
        {
           
          $Controller = $ClusterTB.Text
          $MyloginId = $LoginIdTB.Text
          $passwd =  $PwdTB.Text 
         
              
     
           $LoginPwd = ConvertTo-SecureString -String $passwd -AsPlainText -Force
     
           $credential = New-Object System.Management.Automation.PSCredential $MyloginId,$LoginPwd
     
           Connect-NcController $Controller -Credential $credential
         
        })


    Monday, March 25, 2019 5:00 PM
  • $LoginPwd = ConvertTo-SecureString -String $PwdTB.Text -AsPlainText -Force
    $credential = New-Object System.Management.Automation.PSCredential($LoginIdTB.Text, $LoginPwd)
    Connect-NcController $ClusterTB.Text -Credential $credential

    A textbox is a variable.  In a form it does not need to be saved - just reference it.

    \_(ツ)_/

    • Proposed as answer by Proed Tuesday, March 26, 2019 5:58 AM
    • Marked as answer by Vinay K Singh Wednesday, March 27, 2019 3:41 AM
    Monday, March 25, 2019 5:14 PM
  • excellent, it worked when i execute it using powershell, but when i try to execute it using the forms, it doesnt execute. seems i am missing somthing. 
    Monday, March 25, 2019 6:03 PM
  • Put a button on your form and paste my exact code into the button.  Run the form.


    \_(ツ)_/

    Monday, March 25, 2019 6:24 PM
  • excellent, it worked for me.

    now, i need to create a pop-up window for failed credentials. i created a small form which contains a small message like login failed, in need to integrate it with the Credential form. can you please assist. I am beginner in Powershell. 

    Tuesday, March 26, 2019 4:40 AM
  • Here is a good place for beginners to start:

          Microsoft Virtual     Academy - Getting Started with Microsoft PowerShell


    \_(ツ)_/

    Tuesday, March 26, 2019 4:44 AM