how to create ad user with some requirements in powershell? -
i have create aduser's. password should first 6 characters of id card , last name. should divide full name first name , last name.
this script, did not work:
$userslist = import-csv "c:\teacherslist.csv" foreach ($user in $userslist){ $name = $user.fullname -split '\s+' $firstname = $name[0] $lastname = $name[1] $pass = $user.idcard.substring(0,6)+$lastname new-aduser -name $user.staffid -givenname $firstname -surname $lastname -displayname $user.fullname -accountpassword (convertto-securestring $pass -asplaintext -force) -path 'ou=teacher,dc=school,dc=com' -homedrive 'f:' -changepasswordatlogon $true }
ok, getting parsing issues arguments on different lines that. understand makes easier read, powershell doesn't know next line contains parameter new-aduser cmdlet unless put backtick @ end of each line (must last character of line).
if want keep parameters organized better way assign them variable hashtable , splat hashtable parameters new-aduser.
foreach ($user in $userslist){ $name = $user.fullname -split '\s+' $firstname = $name[0] $lastname = $name[1] $pass = $user.idcard.substring(0,6)+$lastname $params = @{'name' = $user.staffid; 'givenname' = $firstname; 'surname' = $lastname; 'displayname' = $user.fullname; 'accountpassword' = (convertto-securestring $pass -asplaintext -force); 'path' = 'ou=teacher,dc=school,dc=com'; 'homedrive' = 'f:'; 'changepasswordatlogon' = $true} new-aduser @params }