PowerShell - Password Generator - How to always include number in string?

前端 未结 8 1608
长情又很酷
长情又很酷 2020-12-19 06:17

I have the following PowerShell script that creates a random string of 15 digits, for use as an Active Directory password.

The trouble is, this works great most of t

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 06:57

    I had the same issue here is the snippet I used to create my alphanumerical password its simple all I have done is used ASCII regex replace to make it nice.

    Function Password-Generator ([int]$Length)
    {
        # Generate passwords just call password-generator(lenght of password)
        $Assembly = Add-Type -AssemblyName System.Web
        $RandomComplexPassword = [System.Web.Security.Membership]::GeneratePassword($Length,2)
        $AlphaNumericalPassword = $RandomComplexPassword -replace '[^\x30-\x39\x41-\x5A\x61-\x7A]+'
        Write-Output $AlphaNumericalPassword
    }
    

提交回复
热议问题