1

I am trying to add a network group on our domain to the local administrators group on the machine.

I debug line by line and it finds the local administrator group, it finds the network group but when it gets to this line:

AdministratorsGrp.Members.Add(NetworkGrp)

It returns an error "The network path was not found"

How do I fix this error, I spent 30 minutes searching the interwebs and couldn't find a solution :(

Here is my function thus far:

Private Function AddAdminGroup() As Boolean
    Dim AdministratorsGrp As GroupPrincipal
    Dim NetworkGrp As GroupPrincipal

    Try
        Dim DomainCtx As New PrincipalContext(ContextType.Domain, "<domainname>", "<username>", "<pw>")

        'Find Local Administrators group by SID
        AdministratorsGrp = GroupPrincipal.FindByIdentity(DomainCtx, IdentityType.Sid, "S-1-5-32-544")

        'Find Desktop Managers group by Name on Domain
        NetworkGrp = GroupPrincipal.FindByIdentity(DomainCtx, IdentityType.Name, "<network group")

        'Add Desktop Managers group to Administrators Group
        AdministratorsGrp.Members.Add(DesktopMGRGrp)

        'Save Group
        AdministratorsGrp.Save()

        Return True
    Catch PrinEx As PrincipalExistsException
        Return True
    Catch ex As Exception

    End Try
    Return False
End Function

Thanks in advance for any help provided!!

JoshF
  • 159
  • 4
  • 15
  • Have you tried adding Domain\NetworkGrp? – Lance May 15 '15 at 18:09
  • Where did you want me to try adding to? Just to repeat myself it finds the network group, and returns it to that NetworkGrp object. On the machine throwing the error I was able to retrieve properties from that object like SID, and Name and they are correct. – JoshF May 15 '15 at 18:42
  • There's a '>' missing near the end if this line: NetworkGrp = GroupPrincipal.FindByIdentity(DomainCtx, IdentityType.Name, " – Lance May 15 '15 at 19:12
  • I am replacing real values with < fake value > for this website and I missed the >. The real value, the actual name of our network group is correct. The other correct you noticed was me missing something when I was renaming/scrubbing data for public consumption. Those object names are the same in the real code. – JoshF May 15 '15 at 19:15
  • Okay then, sorry. I have nothing more. – Lance May 15 '15 at 19:16

1 Answers1

0

I fixed this problem by changing this line:

Dim DomainCtx As New PrincipalContext(ContextType.Domain, "<domainname>", "<username>", "<pw>")

to

Dim DomainCtx As New PrincipalContext(ContextType.Domain)

I'm not sure why but providing credentials for the domain was causing a problem.

JoshF
  • 159
  • 4
  • 15