Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
April 20, 2005
I have scripted LocalGroupMembership.bat to retrieve up to 2 local groups that the logged on domain user is a member of. The script uses the Local Group Memberships line returned by the net user "%UserName%" /domain command.
The syntax for using LocalGroupMembership.bat is:
LocalGroupMembership Group1 Group2
Where Group1 and Group2 are call directed environment variables that will contain the NetBIOS group name, or NONE.
LocalGroupMembership.bat contains:
@echo offif {%2}=={} @echo Syntax: LocalGroupMembership Group1 Group2&goto :EOFsetlocalfor /f "Tokens=*" %%a in ('net user "%UserName%" /domain^|Findstr /I /B /L /C:"Local Group Memberships *"') do set line=%%aif not defined line endlocal&goto :EOFfor /f "Tokens=2,3 Delims=*" %%a in ('@echo %line%') do ( set lg1=%%a# set lg2=%%b)if defined lg1 set lg1=%lg1: #=%if not defined lg1 set lg1=NONEif not defined lg2 set lg2=NONEendlocal&set %1=%lg1%&set %2=%lg2%
You May Also Like