Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell Script to add managed service accounts Errors out

$
0
0

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.NewADServiceAccount

Anyone see anything wrong with the script or a better way to do this?

Thanks


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>