Trying to create a script to create a bunch of managed service accoutns at once from a csv file. the script is pretty basic:
# import the AD module
if (-not (Get-Module ActiveDirectory)) {Import-Module ActiveDirectory -ErrorAction Stop}
$UserList = IMPORT-CSV E:\SqlLogins\ManagedAccts.csv
FOREACH($Account in $UserList) {
New-ADServiceAccount -Name $Account -Path "LDAP path" -SamAccountName $Account
}The csv file has these three items in it:
SVC.TOBY.OLAIMS,SVC.TOBY.RTest1,SVC.TOBY.Rtest2
when I run the script it throws this error:
New-ADServiceAccount : The name provided is not a properly formed account name
At C:\Users\toby-rpace-a\Documents\Powershell\CreateAccountfromCSV.ps1:11 char:21+ New-ADServiceAccount <<<< -Name $Account -Path "Ldap Path" -SamAccountName $Account+ CategoryInfo : NotSpecified: (CN=@{SVC.TOBY.O...,ldapPart:String) [New-ADServiceAccount], ADException+ FullyQualifiedErrorId : The name provided is not a properly formed account name,Microsoft.ActiveDirectory.Management.Commands.NewADServiceAccountAnyone see anything wrong with the script or a better way to do this?
Thanks