r/PowerShell•
GUTIF

[Question]How to reset an AD password via Powershell without being prompted for the password

I'm trying to write a script that will automatically pass the new password as a variable but for some reason Powershell is still prompting for the password. I'm trying to automate this through Jenkins, but Jenkins keeps erroring out saying Powershell is running in "Noninteractive Mode"

Here is my code:

import-module activedirectory

$pass = "NewPassword"
$username = "Username"

$newpass = ConvertTo-SecureString $pass -AsPlainText -Force
Set-ADAccountPassword -Identity $username -NewPassword $newPassword -Reset

In the Actual jenkins config I wont have these static "Username" and "Password" fields, they will be replaced with environment variables. based on a users input. I set them as static here for testing purposes.

Posted Oct 26, 2016, 4:24 PM UTC

53
justint420•

Because your CMDLET has "$newPassword" for the variable, but you actually named the variable "$newpass" ?

6
GUTIFOP•

That fixed it

https://media.giphy.com/media/6OWIl75ibpuFO/giphy.gif

Thanks for your help!

6
jheinikel•

You could also do it like this and eliminate line 2:

$newPassword = "NewPassword" | convertto-securestring -AsPlainText -Force
3