Saturday, March 5, 2016

Powershell set LDAP user default password from csv list

$user = 'abc\testadmin'
$pass = 'passtest'
$login = New-Object System.Management.Automation.PSCredential -ArgumentList @($user,(ConvertTo-SecureString -String $pass -AsPlainText -Force))

Import-Module ActiveDirectory
$list=IMPORT-CSV "C:\myLdap\ldapuserlist.csv"
echo "Setting pasword"
foreach($_ in $list)
{
$Uname="cn=" + $_.UserName + ",CN=Users,DC=tech-jockey,DC=com"

Set-ADAccountPassword –Identity $Uname -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "default-password" –Force) -Partition "DC=tech-jockey,DC=com" -Credential $login -server 192.168.1.100:78910

Enable-ADAccount -Identity $Uname  -Credential $login -Partition "DC=tech-jockey,DC=com" -server 192.168.1.100:78910
}
echo "Completed"

No comments:

Post a Comment

Thanks for showing interest in tech-jockey.

Content of this blog has been moved to GITHUB

Looking at current trends and to make my content more reachable to people, I am moving all the content of my blog https://tech-jockey.blogsp...