最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

The CMD command to extract username, group name, and permissions from manually created users and not inbuilt is showing a FindST

programmeradmin4浏览0评论

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.

Share Improve this question edited 21 hours ago Stephan 56.2k10 gold badges65 silver badges95 bronze badges asked 23 hours ago SumitSumit 112 bronze badges New contributor Sumit is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

See 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 the Name value;
  • %%u to remove the ending carriage return in the value returned
发布评论

评论列表(0)

  1. 暂无评论