I have installed Windows 2012 server Core only so I can only use command prompt. I created certain users in groups and given them permissions to write, read, delete etc. Now I wish to use the cmd to extract the following data: username, group name, and various permissions given only from my own manually created users and not built-in users.
Please help. Thank you!
This is the code i used:
(
for /f "skip=1 tokens=1 delims=," %u in ('wmic useraccount where "LocalAccount=True and SID LIKE 'S-1-5-%'" get Name /format:csv ^| findstr /V /I "Name"') do (
echo Username: %u
echo Groups:
net user %u | findstr /I "Local Group"
echo Permissions:
icacls "C:\Company" /T /C | findstr /I "%u"
)
) >> UserPermissions.txt
And this is the error:
[FindSTR: Cannot open](.png)
I have tried many different things like wmic
and net user
and tried to make changes everywhere but it didn't work. I can get the two commands separately, ie, I can filter to show only my own created users and I can show permissions for all users. But I can't seem to get both.
I have installed Windows 2012 server Core only so I can only use command prompt. I created certain users in groups and given them permissions to write, read, delete etc. Now I wish to use the cmd to extract the following data: username, group name, and various permissions given only from my own manually created users and not built-in users.
Please help. Thank you!
This is the code i used:
(
for /f "skip=1 tokens=1 delims=," %u in ('wmic useraccount where "LocalAccount=True and SID LIKE 'S-1-5-%'" get Name /format:csv ^| findstr /V /I "Name"') do (
echo Username: %u
echo Groups:
net user %u | findstr /I "Local Group"
echo Permissions:
icacls "C:\Company" /T /C | findstr /I "%u"
)
) >> UserPermissions.txt
And this is the error:
[FindSTR: Cannot open](https://i.sstatic/xHnNGziI.png)
I have tried many different things like wmic
and net user
and tried to make changes everywhere but it didn't work. I can get the two commands separately, ie, I can filter to show only my own created users and I can show permissions for all users. But I can't seem to get both.
1 Answer
Reset to default 0See Dave Benham's WMIC
and FOR /F
: A fix for the trailing <CR>
problem
Try the following .BAT
script (omitted recursion in icacls
to reduce output [merely for debugging]):
@echo off
setlocal
for /F "tokens=2 delims==" %%U in ('
wmic useraccount where "LocalAccount=True and SID LIKE 'S-1-5-%%' and Status<>'Degraded'" get Name /Value
') do (
for /F "tokens=*" %%u in ("%%U") do (
echo Username: %%u
echo Groups
net user %%u | findstr /I "Local Group"
echo Permissions
icacls "C:\Company" /C | findstr /I "%%u"
)
)
REM >> UserPermissions.txt
goto :eof
Here the for
loops are
%%U
to retrieve theName
value;%%u
to remove the ending carriage return in the value returned