Hi All,<\/p>\n
As I am totally rubbish at PowerShell and coding in general, I have looked everywhere for a script that can add multiple AD User accounts for me.<\/p>\n
The majority of the scripts that I tried, have many attributes which I don’t need and yet I still can’t get the scripts to work.<\/p>\n
The user accounts I am creating are test accounts (approx 150) and have the same attributes:<\/p>\n
Firstname
\nSAM
\nOU
\nPassword
\nDescription<\/p>\n
So I have tried to adapt this script I found, but for love, nor money I cannot get it to work:<\/p>\n
$Users = Import-Csv -Path “C:\\Temp\\testaccts.csv” I get the error “ConvertTo-SecureString : The argument cannot be bound to the “String” parameter because it is NULL.”<\/p>\n I have spent ages looking how to fix this issue with no luck As a workaround, I managed to put together some lines of code (don’t ask me how!!!), but it works, for a single account:<\/p>\n $secpass = ConvertTo-SecureString -String “P@ssw0rd” -AsPlainText -Force Anyone with PowerShell skills that could tell me how I can get a script working, as I can’t be bothered doing it manually for 150 test user accounts…<\/p>\n Thanks,<\/p>\n Mak<\/p>","upvoteCount":6,"answerCount":13,"datePublished":"2021-02-08T10:15:14.000Z","author":{"@type":"Person","name":"user2050487680","url":"https://community.spiceworks.com/u/user2050487680"},"suggestedAnswer":[{"@type":"Answer","text":" Hi All,<\/p>\n As I am totally rubbish at PowerShell and coding in general, I have looked everywhere for a script that can add multiple AD User accounts for me.<\/p>\n The majority of the scripts that I tried, have many attributes which I don’t need and yet I still can’t get the scripts to work.<\/p>\n The user accounts I am creating are test accounts (approx 150) and have the same attributes:<\/p>\n Firstname So I have tried to adapt this script I found, but for love, nor money I cannot get it to work:<\/p>\n $Users = Import-Csv -Path “C:\\Temp\\testaccts.csv” I get the error “ConvertTo-SecureString : The argument cannot be bound to the “String” parameter because it is NULL.”<\/p>\n I have spent ages looking how to fix this issue with no luck As a workaround, I managed to put together some lines of code (don’t ask me how!!!), but it works, for a single account:<\/p>\n $secpass = ConvertTo-SecureString -String “P@ssw0rd” -AsPlainText -Force Anyone with PowerShell skills that could tell me how I can get a script working, as I can’t be bothered doing it manually for 150 test user accounts…<\/p>\n Thanks,<\/p>\n Mak<\/p>","upvoteCount":6,"datePublished":"2021-02-08T10:15:14.000Z","url":"https://community.spiceworks.com/t/creation-of-multiple-ad-test-user-accounts/789934/1","author":{"@type":"Person","name":"user2050487680","url":"https://community.spiceworks.com/u/user2050487680"}},{"@type":"Answer","text":" Hi and thanks for your query. I’ve written a script to do just this for my last PowerShell books, you can get it at:<\/p>\n
\nforeach ($User in $Users)
\n{
\n$Displayname = $User.Firstname
\n$UserFirstname = $User.Firstname
\n$OU = “$User.OU”
\n$SAM = $User.SAM
\n$UPN = $User.Firstname + “@test.local<\/span>”
\n$Description = $User.Description
\n$Password = $User.Password
\nNew-ADUser -Name “$Displayname” -DisplayName “$Displayname” -SamAccountName $SAM -UserPrincipalName $UPN -GivenName “$UserFirstname” -Description “$Description” -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path “$OU” -ChangePasswordAtLogon $true –PasswordNeverExpires $true
\n}<\/p>\n<\/p>\n
\nNew-ADUser -Name “TestUser001” -GivenName “TestUser001” -SamAccountName TestUser001 -UserPrincipalName “[email protected]” -Description “Created For Systems Test - TestUser001” -DisplayName “TestUser001” -CannotChangePassword:$true -PasswordNeverExpires:$true -AccountPassword $secpass -Path “OU=Users,OU=IT,OU=UK,OU=Global,DC=test,DC=gwa,DC=local” -Enabled:$true
\nWrite-Host “Account TestUser001 Created”<\/p>\n
\nSAM
\nOU
\nPassword
\nDescription<\/p>\n
\nforeach ($User in $Users)
\n{
\n$Displayname = $User.Firstname
\n$UserFirstname = $User.Firstname
\n$OU = “$User.OU”
\n$SAM = $User.SAM
\n$UPN = $User.Firstname + “@test.local<\/span>”
\n$Description = $User.Description
\n$Password = $User.Password
\nNew-ADUser -Name “$Displayname” -DisplayName “$Displayname” -SamAccountName $SAM -UserPrincipalName $UPN -GivenName “$UserFirstname” -Description “$Description” -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path “$OU” -ChangePasswordAtLogon $true –PasswordNeverExpires $true
\n}<\/p>\n<\/p>\n
\nNew-ADUser -Name “TestUser001” -GivenName “TestUser001” -SamAccountName TestUser001 -UserPrincipalName “[email protected]” -Description “Created For Systems Test - TestUser001” -DisplayName “TestUser001” -CannotChangePassword:$true -PasswordNeverExpires:$true -AccountPassword $secpass -Path “OU=Users,OU=IT,OU=UK,OU=Global,DC=test,DC=gwa,DC=local” -Enabled:$true
\nWrite-Host “Account TestUser001 Created”<\/p>\n