First row of csv must be

user,pass

$strComputer=$env:computername

$csv = Import-CSV ./users.csv

ForEach ($user in $csv ){

Create the user account and assign a default password

$objOU = [adsi]”WinNT://.”
$objUser = $objOU.Create(“User”, $user.user)
$objuser.setPassword($user.pass)
$objuser.setinfo()

Enable [PasswordNeverExpires]

Set-LocalUser -Name $user.user -PasswordNeverExpires:$true

Add the User account to the local users Group

$computer = [ADSI](“WinNT://” + $strComputer + “,computer”)
$group = $computer.psbase.children.find(“Users”)
$group.Add(“WinNT://” + $strComputer + “/” + $user.user)

Add the User account to the local users Group

$computer = [ADSI](“WinNT://” + $strComputer + “,computer”)
$group = $computer.psbase.children.find(“Remote Desktop Users”)
$group.Add(“WinNT://” + $strComputer + “/” + $user.user)

}

Leave a Reply

Your email address will not be published. Required fields are marked *