Cannot add user to local group.

This topic contains 4 replies, has 4 voices, and was last updated by  Johnny Leuthard 2 years, 3 months ago.

  • Author
  • #36863

    Bruce Markey

    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

  • #36867

    Bob McCoy

    Try using a subexpression.

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

    Bruce Markey


    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: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : CatchFromBaseAdapterMethodInvokeTI

  • #36883

    Jonathan Warnken

    Simple fix see

    use the path when adding

  • #36915

    Johnny Leuthard

    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?

You must be logged in to reply to this topic.