Cannot add user to local group.

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

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.


$objgroup = [ADSI]"WinNT://RadiusSVR/TEST,group" 
$target = [ADSI]"WinNT://RadiusSVR"

Import-Csv testlist1.csv | ForEach-Object { 
$newuser = $target.Create("user", $_.MAC) 
$newuser.FullName = ($_.NAME)
$newuser.psbase.InvokeSet('AccountDisabled', $false) 

$objuser = [ADSI]"WinNT://RadiusSVR/" + $_.MAC


Method invocation failed because [System.DirectoryServices.DirectoryEntry] does not contain a method named
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

Try using a subexpression.

$objuser = [ADSI]"WinNT://RadiusSVR/$($_.MAC)"


Tried that. I get type mismatch errors.

I got it working by using net commands instead. I’ve tried like a dozen suggestions to get this to work and at this point I don’t believe it can.

Here is the error I get when I try that.

Exception calling "Add" with "1" argument(s): "Type mismatch. (Exception from   HRESULT: 0x80020005
At C:\Users\Administrator\Desktop\Import Script\Import1.ps1:14 char:2
+     $objgroup.Add($objuser)
  • ~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:slight_smile: [], MethodInvocationException
    • FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

Simple fix see

use the path when adding


Looks to me like it’s balking at
$objuser = [ADSI]“WinNT://RadiusSVR/” + $_.MAC

‘op_Addition’ makes the ‘+’ in + $.MAC jump out at me.
Maybe enclose it all in ()
( [ADSI]“WinNT://RadiusSVR/” + $
.MAC )
Or maybe try
Depending on the PS version you are using.

If using POSH3 or higher perhaps try creating a Desired State Push Script that says what accounts and groups must be present and what memberships each group must have?