Script to create Multiple local Users and set Password never Expire

function create-account ([string]$accountName) {

 $hostname = hostname

 $comp = [adsi]"WinNT://$hostname"

 $user = $comp.Create("User", $accountName)

 $user.SetPassword("P@ssw0rd")

 #$user.SetInfo()

 $User.UserFlags[0] = $User.UserFlags[0] -bor 0x10000 #ADS_UF_DONT_EXPIRE_PASSWD flag is 0x10000

 $user.SetInfo()}

 # Create 30 administrator users named user1 ... user 30

for($i=20; $i -le 23; $i++){

  create-account("TRAIN-$i")

  }


No comments:

Post a Comment

Featured Post

HPE MSA 2040 configuration step by step

HPE MSA 2040 configuration Default IP range for HP SAN storage MSA 2040 is 10.0.0.1/2 You need to connect your laptop and storage with...