Last active
January 26, 2025 23:25
-
-
Save ILPlais/8ed013bff42aa8b2e63923fdbba94dd4 to your computer and use it in GitHub Desktop.
Batch script to retrieve local user group names independent of system language under Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @ECHO OFF | |
| SETLOCAL EnableDelayedExpansion | |
| REM Usage: GetLocalGroupName.cmd [SID] | |
| REM If there is no parameter, display the list of local groups | |
| REM If there is a parameter, use it as the SID | |
| REM If there is no parameter, display the list of local groups | |
| IF [%1] == [] ( | |
| ECHO Choice from the English name the local group to get on this system: | |
| ECHO 1. Administrators | |
| ECHO 2. Users | |
| ECHO 3. Guests | |
| ECHO 4. Power Users | |
| ECHO 5. Accout Operators | |
| ECHO 6. Server Operators | |
| ECHO 7. Print Operators | |
| ECHO 8. Backup Operators | |
| ECHO 9. Replicators | |
| ECHO C. Custom SID | |
| CHOICE /C "123456789C" /M "Your choice: " | |
| SET "USERCHOICE=!ERRORLEVEL!" | |
| GOTO UserChoice | |
| ) | |
| REM If there is a parameter, use it as the SID | |
| IF [%1] NEQ [] ( | |
| SET "SID=%1" | |
| GOTO GetGroupName | |
| ) | |
| :UserChoice | |
| REM Administrators | |
| IF %USERCHOICE% EQU 1 GOTO Administrators | |
| REM Users | |
| IF %USERCHOICE% EQU 2 GOTO Users | |
| REM Guests | |
| IF %USERCHOICE% EQU 3 GOTO Guests | |
| REM Power Users | |
| IF %USERCHOICE% EQU 4 GOTO PowerUsers | |
| REM Accout Operators | |
| IF %USERCHOICE% EQU 5 GOTO AccoutOperators | |
| REM Server Operators | |
| IF %USERCHOICE% EQU 6 GOTO ServerOperators | |
| REM Print Operators | |
| IF %USERCHOICE% EQU 7 GOTO PrintOperators | |
| REM Backup Operators | |
| IF %USERCHOICE% EQU 8 GOTO BackupOperators | |
| REM Replicators | |
| IF %USERCHOICE% EQU 9 GOTO Replicators | |
| REM Custom SID | |
| IF %USERCHOICE% EQU 10 GOTO CustomSID | |
| REM Param SID | |
| IF %USERCHOICE% EQU 11 GOTO ParamSID | |
| :Administrators | |
| SET SID=S-1-5-32-544 | |
| GOTO GetGroupName | |
| :Users | |
| SET SID=S-1-5-32-545 | |
| GOTO GetGroupName | |
| :Guests | |
| SET SID=S-1-5-32-546 | |
| GOTO GetGroupName | |
| :PowerUsers | |
| SET SID=S-1-5-32-547 | |
| GOTO GetGroupName | |
| :AccoutOperators | |
| SET SID=S-1-5-32-548 | |
| GOTO GetGroupName | |
| :ServerOperators | |
| SET SID=S-1-5-32-549 | |
| GOTO GetGroupName | |
| :PrintOperators | |
| SET SID=S-1-5-32-550 | |
| GOTO GetGroupName | |
| :BackupOperators | |
| SET SID=S-1-5-32-551 | |
| GOTO GetGroupName | |
| :Replicators | |
| SET SID=S-1-5-32-552 | |
| GOTO GetGroupName | |
| :CustomSID | |
| ECHO Type the SID you want to get. | |
| ECHO The list can be found here: | |
| ECHO https://learn.microsoft.com/windows-server/identity/ad-ds/manage/understand-security-identifiers#well-known-sids | |
| SET /P SID="SID: " | |
| GOTO GetGroupName | |
| :GetGroupName | |
| REM Get the group name | |
| SET WMIC_CMD=WMIC GROUP WHERE "LocalAccount=True AND SID='%SID%'" GET Name /VALUE | |
| FOR /F "delims=" %%A IN ('%WMIC_CMD% ^| FIND "="') DO SET %%A | |
| REM Display the local name of the groupe | |
| ECHO %Name% | |
| ENDLOCAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment