Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Where to put -ChangePasswordAtLogon switch?

$
0
0

Hello gentleman.

I have been snooping around it the script below, i am trying to figure out where to put the -ChangePasswordAtLogon switch so the newly created users must change passsword at first logon.

The users are being imported via an .csv file. Everything works great, i have tried with some different codes, but no luck yet.

$OUPath = "LDAP://$MassUsersOU,$DomainDN"

$UserPath = [ADSI]"$OUPath"
Write-Host "---------------------------------------------------------------"
Write-Host "Creating LAB Users"
Write-Host "Version 1.0"
Write-Host "---------------------------------------------------------------"

Foreach ($User in $UserInformation){

$CN = $User.samAccountName
$SN = $User.Surname
$Given = $User.givenName
$samAccountName = $User.samAccountName
        $MA = $User.MA
$Display = $User.DisplayName

$LABUser = $UserPath.Create("User","CN=$CN")
Write-Host "Creating User: $User.samAccountName"
$LABUser.Put("samAccountName",$samAccountName)
$LABUser.Put("sn",$SN)
$LABUser.Put("givenName",$Given)
$LABUser.Put("displayName",$Display)
#Description
    $LABUser.Put("description", "MassUser - created via Script")
$LABUser.Put("userPrincipalName","$MA@$domain")
$LABUser.SetInfo()

$Pwrd = $User.Password

$LABUser.psbase.invoke("setPassword",$Pwrd)
$LABUser.psbase.invokeSet("AccountDisabled",$False)
$LABUser.psbase.CommitChanges()

}
Write-Host "Script Completed"

In advance, thanks!


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>