I’m attempting to import a bunch of users from a csv into local users, then add them to a group. The username and password are set to a mac address, this is for mac authentication.
The import works fine. All users are created but it just will not add them to a local group.
( I based my work off of this post. Local Users and Groups | Richard Siddaway's Blog )
My guess is that it’s not concatenating correctly and thats the issue, but I’m not really sure. I’ve done very little with powershell.
Code:
$objgroup = [ADSI]"WinNT://RadiusSVR/TEST,group"
$target = [ADSI]"WinNT://RadiusSVR"
Import-Csv testlist1.csv | ForEach-Object {
$newuser = $target.Create("user", $_.MAC)
$newuser.SetPassword($_.MAC)
$newuser.SetInfo()
$newuser.FullName = ($_.NAME)
$newuser.SetInfo()
$newuser.psbase.InvokeSet('AccountDisabled', $false)
$newuser.SetInfo()
$objuser = [ADSI]"WinNT://RadiusSVR/" + $_.MAC
$objgroup.Add($objuser)
}
Error:
Method invocation failed because [System.DirectoryServices.DirectoryEntry] does not contain a method named
‘op_Addition’.
At C:\Users\Administrator\Desktop\Import Script\Import1.ps1:13 char:2
-
$objuser = [ADSI]"WinNT://RadiusSVR/" + $_.MAC
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (op_Addition:String) , RuntimeException
- FullyQualifiedErrorId : MethodNotFound
Exception calling “Add” with “1” argument(s): "An invalid directory pathname was passed