PowerShell: expose the password policy engine (generate + validate)

PowerShell: expose the password policy engine (generate + validate)

1 vote

avatar

Hello,

We're opening this FR on behalf of a client.

Get-DSPasswordPolicy reads a DVLS password template, but nothing in the module can actually use it - no cmdlet generates a password from a policy, and none validates a password against one.

So, we would like to request that the existing cmdlet be extended, or that a new cmdlet be added, for:

  • New-DSRandomPassword -PolicyName 'Standard'
  • Test-DSPassword -Password <string> -PolicyName 'Standard' (returning the unmet criteria)
  • a -PolicyName parameter on New-DSCredentialEntry


The workaround for now would be the following code block:

$pol = Get-DSPasswordPolicy -Name 'Standard'
if (-not $pol) { throw "Policy not found" }

$pwd = [Devolutions.RemoteDesktopManager.Business.PasswordGeneratorHelper]::Generate($pol)

# Verify in advance whether the generated password meets the policy requirements
"Requirements: " + [Devolutions.Server.Managers.PasswordValidationManager]::GetWarningDetails($pwd, $pol)

$new = New-DSCredentialEntry -Name 'srv01-admin' -Username 'admin' -Password $pwd

$e = Get-DSEntry -EntryID $new.ID -AsRDMConnection
$e.ConnectionInfo |
  Set-DSEntryProperty -Path 'Credentials' -PropertyName 'Password'                        -PropertyValue $pwd |
  Set-DSEntryProperty -Path 'Security'    -PropertyName 'PasswordComplexityId'            -PropertyValue $pol.ID |
  Set-DSEntryProperty -Path 'Security'    -PropertyName 'PasswordComplexityUsageOverride' -PropertyValue 'Enabled' |
  Update-DSEntryBase


Thanks!

Best regards,

Gerhard Ryznar

All Comments (0)