Creating Users from Arrays in Powershell -


hello i'm using active directory while , want make user creation script arrays learn how works , yes know can make csv , import , works magic know want use powershell , new-aduser , arrays make accounts loop

i made code because new in powershell skills noobish

$pwd = convertto-securestring -string "pa$$w0rd" -asplaintext -force $name = read-host -prompt 'input username' $ou = read-host -prompt 'input ou' new-aduser $name -accountpassword $pwd -changepasswordatlogon $false -passwordneverexpires $true -path "ou=$ou,dc=contoso,dc=com" enable-adaccount -identity $name 

what wanted know , couldn't find lot of info how make arrays of ou's , arrays of usernames , ou's , make command roll 5-10 times , reason want learn more powershell , see how works , can go it

edit: ok played little powershell , foreach , ended this

$userarray = ('bi','ba','bo') foreach ($user in $userarray) { new-aduser $user -samaccountname $user -accountpassword $pwd -changepasswordatlogon $false -passwordneverexpires $true -path "ou=labs,dc=contoso,dc=com" enable-adaccount -identity $user } 

now ou , how make command lets me add things inside array start writing names after ended adding names want , name goes ou runs command

edit2: ok after work , examples got reason creates user testing in ou sales , cant understand why

$pwd = convertto-securestring -string "pa$$w0rd" -asplaintext -force $a = @('test1','sales2','labs3') $b = @('testing','sales','labs') $values = $a,$b $user = $values[0] $ou = $values[1]  foreach-object { new-aduser $user -samaccountname $user -accountpassword $pwd -changepasswordatlogon $false -passwordneverexpires $true -path "ou=$ou,dc=contoso,dc=com" enable-adaccount -identity $user } 

and of time gives me errors -samaccountname strings

use , array of arrays, or array of hash sets.

play around code , incorporate project.

$newusersinou1 = @() $newusersinou1 += "ou=labs,dc=contoso,dc=com", "ba" $newusersinou1 += "ou=office,dc=contoso,dc=com", "bb" $newusersinou1 += "ou=hq,dc=contoso,dc=com", "bc" $newusersinou1 += "ou=labs,dc=contoso,dc=com", "bd" $newusersinou1 | ft -autosize  ## or   $newusersinou2 = @() $newusersinou2 += @{ou="ou=labs,dc=contoso,dc=com"; user="ba"} $newusersinou2 += @{ou="ou=office,dc=contoso,dc=com"; user="bb"} $newusersinou2 += @{ou="ou=hq,dc=contoso,dc=com"; user="bc"} $newusersinou2 += @{ou="ou=labs,dc=contoso,dc=com"; user="bd"} $newusersinou2 | ft -autosize  $newusersinou2[1].ou $newusersinou2[1].user 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -