Generating Random password for user accounts in AD

Welcome Forums General PowerShell Q&A Generating Random password for user accounts in AD

  • This topic has 4 replies, 4 voices, and was last updated 1 month ago by
    Participant
    .
Viewing 3 reply threads
  • Author
    Posts
    • #279888
      Participant
      Topics: 10
      Replies: 11
      Points: 145
      Rank: Participant

      Hi Everyone,

      I am trying to generate a random password for user accounts in AD, Is there a way I can eliminate generating non alphanumeric characters?

       

      Function GenerateNewPassword{
      [System.Web.Security.Membership]::GeneratePassword(8,0)
      $PasswordLenth = ‘8’
      $NonAlphaNumeric = ‘0’
      $SecurePassword = [System.Web.Security.Membership]::GeneratePassword($PasswordLenth,$NonAlphaNumeric)

      }
      GenerateNewPassword

    • #279906
      Participant
      Topics: 12
      Replies: 547
      Points: 1,345
      Helping Hand
      Rank: Community Hero
    • #279966
      Participant
      Topics: 10
      Replies: 203
      Points: 996
      Helping Hand
      Rank: Major Contributor

      What I fail to understand is why the GeneratePassword method completely ignores the Non Alpha setting. If I say 0, then by god I want 0. 🙂

      There are some simple solutions here. I like the 3 line regex solution.

      https://stackoverflow.com/questions/2625150/membership-generate-password-alphanumeric-only-password

       

      • #280203
        Participant
        Topics: 10
        Replies: 11
        Points: 145
        Rank: Participant

        Thank You Everyone, all these solutions worked great for me.

    • #280005
      Participant
      Topics: 1
      Replies: 96
      Points: 441
      Helping Hand
      Rank: Contributor

      If you don’t know all the ASCII code ranges and don’t have PowerShell v6+, you can opt for an all inclusive ASCII range and use regex matching to filter it down. Then pipe to Get-Random for your length:

      The \p{unicodeProperty} syntax matches on unicode properties. L is letter and N is number.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.