barnyhall
asked on
Powershell User Import Script Server 2012 ADS
Hi looking for a script to create a user account with the below info from a CSV can anyone help?
I have always done this with VBS but in 2012 it doesn't seem to work
sAMAccountName
sn
givenName
displayName
description
password
I have always done this with VBS but in 2012 it doesn't seem to work
sAMAccountName
sn
givenName
displayName
description
password
ASKER
powershell just opens and closes with the above script I have been trying with the below as well which dose seem to run but errors with
you cannot call a method on a null-valued expression
Import-Module ActiveDirectory
$Users = Import-Csv -Delimiter ";" -Path ".\2013.csv"
foreach ($User in $Users)
{
$OU = "OU=test,DC=internal,DC=si te,DC=com"
$Password = $User.password
$Detailedname = $User.firstname + " " + $User.name
$UserFirstname = $User.Firstname
$FirstLetterFirstname = $UserFirstname.substring(0 ,1)
$SAM = $FirstLetterFirstname + $User.name
New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $SAM -DisplayName $Detailedname -GivenName $user.firstname -Surname $user.name -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path $OU
}
you cannot call a method on a null-valued expression
Import-Module ActiveDirectory
$Users = Import-Csv -Delimiter ";" -Path ".\2013.csv"
foreach ($User in $Users)
{
$OU = "OU=test,DC=internal,DC=si
$Password = $User.password
$Detailedname = $User.firstname + " " + $User.name
$UserFirstname = $User.Firstname
$FirstLetterFirstname = $UserFirstname.substring(0
$SAM = $FirstLetterFirstname + $User.name
New-ADUser -Name $Detailedname -SamAccountName $SAM -UserPrincipalName $SAM -DisplayName $Detailedname -GivenName $user.firstname -Surname $user.name -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path $OU
}
Typically the only reason that ve3ofa's wouldn't work would be because of the CSV - if its format is odd, or the headers don't match with the properties called in the script, or if you don't have headers. Can you post a sample of the CSV?
ASKER
sAMAccountName,sn,givenNam e,displayN ame,descri ption,pass word
That's not a lot of help. Is that the header row? Or just an example of what each line contains?
An actual file would be much better with something like the first 3 lines. You can put in some generic info if you want. How is the file created? I've seen issues where a BOM in the file messed up an import, but is not visible in Notepad and some other methods, hence an actual file is more useful.
An actual file would be much better with something like the first 3 lines. You can put in some generic info if you want. How is the file created? I've seen issues where a BOM in the file messed up an import, but is not visible in Notepad and some other methods, hence an actual file is more useful.
ASKER
Example attached thanks
2013.csv
2013.csv
Well, there's no problem with the CSV you provided.
Can you just run the New-ADUser command from the console and just fill in the info for each parameter instead of $user.property? This would be a test trying to limit down where an error might be occurring.
Can you just run the New-ADUser command from the console and just fill in the info for each parameter instead of $user.property? This would be a test trying to limit down where an error might be occurring.
ASKER
can you send me a copy of the script that works for you please
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If my last post with the script (http:#a39238520) helped you, or any other post, please accept those as solutions instead of your own post.
ASKER
script worked thanks
Open in new window