none
Listrar grupos do usuário com JScript RRS feed

  • Pergunta

  • Boa noite!

    Estou tentando criar um script para listar os grupos de um usuário, porém sem sucesso. Vi vários exemplos em VB, testei e funcionaram, porém quando escreve em JScript não funciona. Segue os scripts que tentei:

    Em ambos os casos, em VB funcoina e em JScript não. O que pode ser? O que estou fazendo de errado?  Obrigado!

     

    ######################################################################################

    Dim objNetwork, sDomain, sUser, objUser

    Set objNetwork = CreateObject("WScript.Network")
    sDomain = objNetwork.UserDomain
    sUser = objNetwork.UserName
    Set objUser = GetObject("WinNT://" & sDomain & "/" & sUser)
    Set oShell= CreateObject("Wscript.Shell")

    For each oGroup in objUser.Groups
      wscript.echo oGroup.Name
    Next

    #### EM JSCRIPT #######################################################################

    objNetwork = WScript.CreateObject("WScript.Network");
    sDomain = objNetwork.UserDomain;
    sUser = objNetwork.UserName;
    objUser = GetObject("WinNT://" + sDomain + "/" + sUser);
    oShell= CreateObject("Wscript.Shell");

    for (var oGroup in objUser.Groups) {
      WScript.Echo("Grupo: "+oGroup.Name);
    }

    #######################################################################################
    #######################################################################################

    On Error Resume Next
    Set objSysInfo = CreateObject("ADSystemInfo")
    strUserDN = objSysInfo.UserName
    Set objUser = GetObject("LDAP://" & strUserDN)
    Set objNetwork = CreateObject("Wscript.Network")
    Set objShell = CreateObject("WScript.Shell")
    Set FSO = CreateObject("Scripting.FileSystemObject")

    'Map network share by group
    arrGroups = objUser.GetEx("memberOf")
       For Each strGroup in arrGroups
            Set objGroup = GetObject("LDAP://" & strGroup)
            strGroupName = objGroup.CN
            WScript.Echo strGroup & " # " & strGroupName
    Next

    #### EM JSCRIPT ########################################################################

    objSysInfo = WScript.CreateObject("ADSystemInfo");
    strUserDN = objSysInfo.UserName;
    objUser = GetObject("LDAP://" + strUserDN);
    arrGroups = objUser.GetEx("memberOf")

    for (var strGroup in arrGroups)
          Set objGroup = GetObject("LDAP://" & strGroup);
          strGroupName = objGroup.CN;
          WScript.Echo(strGroup + " # " + strGroupName);
    }
    #######################################################################################

     


    ------------------------------------- Ígor N. M. - NCA Gestão e Consultoria www.ncagestao.com.br # (24) 3349-3984
    domingo, 16 de janeiro de 2011 19:29

Respostas

  • Para quem precisar, a solução:

     

    userDN = objADi.UserName;
    objUser = GetObject("LDAP://"+userDN);
      usrGroups = objUser.GetEx("memberOf").toArray();


    for(var a = 0; a < usrGroups.length; a++) {
        objGroup = GetObject("LDAP://"+usrGroups[a]);
        groupName = objGroup.CN;

        WScript.Echo("Grupo: "+groupName);
    }


    ------------------------------------- Ígor N. M. - NCA Gestão e Consultoria www.ncagestao.com.br # (24) 3349-3984
    • Marcado como Resposta Ígor N. M. _ quarta-feira, 21 de dezembro de 2011 12:20
    quarta-feira, 21 de dezembro de 2011 12:19