Get all th user inside the poweruser and users group in all machines in the domain

Posted on 2007-10-16
Last Modified: 2010-04-16

Get all th user inside the poweruser and users group in all machines in the domain.
Script that can get me all the users inside the "users and Powerusers group"

Question by:bsharath
    1 Comment
    LVL 26

    Accepted Solution

    :: ================
    :: ================
    :: * To run this script you must have domain administrators rights.
    :: * This script require "Computers.txt" file from where it will pick system names.
    :: * Successful run will generate 'LocalGroupMembers.txt' file
    :: * Copy and Paste following script into notepad and save it with any name having .cmd extension.
    SETLOCAL EnableDelayedExpansion
    IF NOT EXIST Computers.txt GOTO ShowErr
    FOR %%R IN (Computers.txt) DO IF %%~zR EQU 0 GOTO ShowErr
    IF EXIST LocalGroupMembers.txt DEL /F /Q LocalGroupMembers.txt
    FOR /F %%c in ('TYPE Computers.txt') DO (
          SET GroupName=Users
          SET Computer=%%c
          ECHO Processing: !Computer!
          PING -n 1 -w 1000 !Computer!|FIND /I "TTL" >NUL
          IF NOT ERRORLEVEL 1 (
                ECHO -------------->>LocalGroupMembers.txt
                ECHO !Computer!>>LocalGroupMembers.txt
                ECHO -------------->>LocalGroupMembers.txt
                ECHO USERS INSIDE: !GroupName!>>LocalGroupMembers.txt
                SET Qry=WMIC /NODE:"!Computer!" PATH Win32_GroupUser WHERE ^(GroupComponent="WIN32_Group.Name=\"!GroupName!\",Domain=\"!Computer!\""^) GET PartComponent /FORMAT:CSV
                FOR /F "Tokens=5 Delims==," %%I IN ('!Qry! 2^>NUL') DO (ECHO       %%~I>>LocalGroupMembers.txt)
                IF "!GroupName!"=="Users" SET GroupName=Power Users&Call :Again))
    GOTO EndScript
    ECHO 'Computers.txt' file does not exist or file is empty!
    :: *** SCRIPT END ***


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This article will show, step by step, how to integrate R code into a R Sweave document
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now