Windows Prompt Box

Welcome Forums General PowerShell Q&A Windows Prompt Box

Viewing 6 reply threads
  • Author
    Posts
    • #204654
      Participant
      Topics: 4
      Replies: 2
      Points: 49
      Rank: Member

      Hi Folks,

      Because our domain name is so long, when the “Windows Powershell Credential Request” box appears; the User Name field is already filled and the user gets confused where to add his/her username.

      Any way to save the domain name in my script so when prompted for credentials; the User Name field is empty and the user will only need to enter his/her AD username? This will then be combined with the domain to be password on for credential check?

      My script:

      I hope I was clear, if not, please ask!

      Thanks in advance 🙂

    • #204657
      Participant
      Topics: 10
      Replies: 210
      Points: 1,023
      Helping Hand
      Rank: Community Hero

      What about

      Get-Credential -Username "$ENV:UserDomain\$ENV:UserName" -Message 'Enter your password'

      This should only require a PW.

      • #204900
        Participant
        Topics: 4
        Replies: 2
        Points: 49
        Rank: Member

        My apologies,

        The usernames are different from the user’s current logged in usernames. So users will need to enter their admin username separately.

    • #204810
      Participant
      Topics: 17
      Replies: 1958
      Points: 4,020
      Helping Hand
      Rank: Community Hero

      Not sure what parts of the credential object get used. The username property is a Read-Only. Using GetNetworkCredential() seems to be entirely different set of properties, which can be set. You can set the Domain, but setting that or the UserName does not change the value of the direct Username property. Worst case, your can basically tear the PSCredential apart and rebuild it with the domain:

    • #204954
      Participant
      Topics: 10
      Replies: 210
      Points: 1,023
      Helping Hand
      Rank: Community Hero

      OK, you say:

      My apologies,

      The usernames are different from the user’s current logged in usernames. So users will need to enter their admin username separately.

      That being the case, and going back to your original script, if they must enter two fields, prompt them for the username, then use that in get cred, they then enter the PW. Either way, they have two fields to enter.

      $UserName = Read-Host 'Enter your ADMIN User Name'

      Get-Credential -Username "$ENV:UserDomain\$UserName" -Message 'Enter your password'

      Am I missing something here? My apology.

      • This reply was modified 11 months, 1 week ago by TonyD.
      • #205227
        Participant
        Topics: 4
        Replies: 2
        Points: 49
        Rank: Member

        This works!

        Only one point to make this work better – When I do the following steps; I get an extra credentials prompt:

        1. Run .ps1
        2. Prompted to enter AD username > entered
        3. Prompted to enter password > clicked Cancel
        4. I get another Windows Powershell credential request but all fields empty. It would be great if this window can be eliminated all together and have the script move on (this only happens if I click cancel again)

        My updated script:

        Otherwise, I will mark this as the answer shortly.

        Thanks for your help!

    • #204996
      Participant
      Topics: 1
      Replies: 20
      Points: 109
      Helping Hand
      Rank: Participant

      Out of curiosity, why is your sign in domain so long?  Can you add a UPN and assign the admin accounts to it?

      I, personally, like things simple, if special things need to be done to accommodate something arbitrary, like the number of keys that need to be pressed in order to log in, I like to try to reduce the monotony enforced on the users of the systems, and a UPN suffix is an easy fix for a long logon domain.

    • #205758
      Participant
      Topics: 10
      Replies: 210
      Points: 1,023
      Helping Hand
      Rank: Community Hero

      The double creds may have to do with your while logic, maybe try this:

      While($TryAgain) {
      ........
            if (($TryAgain = Read-Host) -ne "Y") { break }
      }

       

       

      • This reply was modified 11 months, 1 week ago by TonyD.
      • This reply was modified 11 months, 1 week ago by TonyD.
      • This reply was modified 11 months, 1 week ago by TonyD.
      • This reply was modified 11 months, 1 week ago by TonyD.
    • #206124
      Participant
      Topics: 2
      Replies: 1014
      Points: 2,105
      Helping Hand
      Rank: Community Hero

      You are really over complicating this effort.

      Why are you doing this, and all this console stuff at all…

      Start-Process powershell -Credential (Get-Credential -Username "$ENV:UserDomain\$UserName" -Message 'Enter your password') -ArgumentList "$Env:WinDir\System32\dsa.msc" -ErrorAction Stop

      … Just ask for the user name, pass in the domain with that and move on.

      For example, why not just do:

      # this...
      $UserName = Read-Host 'Please enter your AD Username'
      Start-Process powershell -Credential "$ENV:UserDomain\$UserName" -ArgumentList "$Env:WinDir\System32\dsa.msc"

      # ...Or use dialogs for both and stay out of the console altogether
      [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
      $Title = 'User information'
      $Msg = 'Enter your username:'
      $Username = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $Title)
      Start-Process powershell -Credential "$ENV:UserDomain\$UserName" -ArgumentList "$Env:WinDir\System32\dsa.msc"

       

       

       

Viewing 6 reply threads
  • The topic ‘Windows Prompt Box’ is closed to new replies.