Hi All,
I am trying to create this application to amend a users password dependent on the value within a label. I have created a text box to hold the value which is generated from our system. Preferably I would like it to have one special character and 1 number to keep it secure but I am not sure how to make this simple, I have also hit a road block when it attempts to change the password, AD Powershell states that it is not able to make the text value a secure string. The code is:
Powershell GUI Script:
Add-Type -AssemblyName System.Web
$Assembly = [System.Web.Security.Membership]::GeneratePassword(8, 1)
$richtextbox1.text = $Assembly
$Generated.text = $Assembly
$password = $richtextbox1.Text | ConvertTo-SecureString -AsPlainText -Force
$users = $username.Text | ConvertTo-SecureString -AsPlainText -Force
Set-ADAccountPassword $username.Text -NewPassword $richtextbox1.text -verbose -Reset -PassThru | Set-ADuser $users -ChangePasswordAtNextLogon $true
"Exported Log: $user, $Generated" | out-file output\Output.log -append
Powershell Output:
Set-ADAccountPassword : Cannot bind parameter 'NewPassword'. Cannot convert the "tBG.uvAV" value of type "System.String" to type "System.Security.SecureString".
At Export.ps1:17899 char:52
+ Set-ADAccountPassword $username.Text -NewPassword <<<< $richtextbox1.text -verbose -Reset -PassThru | Set-ADuser $users -ChangePasswordAtNextLogon $true
+ CategoryInfo : InvalidArgument: (:) [Set-ADAccountPassword], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.SetADAccountPassword
Many Thanks all, Craig
Setting AD Password from GUI
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Setting AD Password from GUI
We do not encrypt the username.
Your code does not make much sense. Why are you using "$richtextbox1" when you want a secure string. a Textbox cannot hold a secure string. It can only contain text.
Your code does not make much sense. Why are you using "$richtextbox1" when you want a secure string. a Textbox cannot hold a secure string. It can only contain text.
Re: Setting AD Password from GUI
I attempted to just use a label but it didn't work so I tried a text box instead but it still failed
Re: Setting AD Password from GUI
- Add-Type -AssemblyName System.Web
- $richtextbox1.text = [System.Web.Security.Membership]::GeneratePassword(8, 1)
- $password = $richtextbox1.Text | ConvertTo-SecureString -AsPlainText -Force
- Set-ADAccountPassword $username.Text -NewPassword $password -Reset
- Set-ADuser $username.Text -ChangePasswordAtLogon $true
- $msg = 'Exported Log:{}{}' -f $username.Text, $richtextbox1.text
- Write-Host $msg
- $msg | out-file output\Output.log -append