0

I have an Excel spreadsheet that contains a list of usernames

Each user will have the following code. I just need to find a way to substitute First.Last with the names in the Excel spreadsheet. There are over 800 names and I can do this manually. It is just very tedious.

echo Y | takeown /F "F:\Users\First.Last" /R
icacls "F:\USERS\First.Last" /reset /T /C /Q
icacls "F:\USERS\First.Last" /inheritance:r /T /C /Q
icacls "F:\USERS\First.Last" /grant:r system:(oi)(ci)f /t /c /Q
icacls "F:\USERS\First.Last" /grant:r "Site admins":(oi)(ci)f /t /c /Q
icacls "F:\USERS\First.Last" /grant:r "Domain admins":(oi)(ci)f /t /c /Q
icacls "F:\USERS\First.Last" /grant:r "CREATOR OWNER":(OI)(CI)F /T /C /Q
icacls "F:\USERS\First.Last" /grant:r First.Last:(oi)(ci)f /t /c /Q
icacls "F:\USERS\First.Last" /remove:g "everyone" /T /C /Q
icacls "F:\USERS\First.Last" /remove:g "administrators" /T /C /Q
icacls "F:\USERS\First.Last" /remove Everyone /T /C /Q
icacls "F:\USERS\First.Last" /remove:g "COURTS\administrator.account" /T /C /Q
icacls "F:\USERS\First.Last" /remove "COURTS\administrator.account" /T /C /Q
icacls "F:\Users\First.Last" /setowner "COURTS\First.Last" /c /t /Q
icacls "F:\USERS\First.Last" /inheritance:e /T /C /Q
net share First.Last$ /delete
icacls "F:\USERS\First.Last" /remove:g "system" /T /C /Q
icacls "F:\USERS\First.Last" /remove "system" /T /C /Q
icacls "F:\USERS\First.Last" /remove:g "Site Admins" /T /C /Q
icacls "F:\USERS\First.Last" /remove "Site Admins" /T /C /Q
icacls "F:\USERS\First.Last" /remove:g "Domain Admins" /T /C /Q
icacls "F:\USERS\First.Last" /remove "Domain Admins" /T /C /Q
icacls "F:\USERS\First.Last" /remove:g "Creator Owner" /T /C /Q
icacls "F:\USERS\First.Last" /remove "Creator Owner" /T /C /Q
  • I suggest writing the data to a text file (e.g., CSV or tab delimited) and then working from that. P.S. Since your question involves running Windows commands, you should probably tag your question with the version of Windows that you are using (e.g., [windows-7]). Also, for good measure, what version of Excel are you using? – G-Man Aug 15 '14 at 17:16
1

If you need to get a list of names from excel then copy and paste the list of names into notepad and save as names.txt as below.

pretend contents of names.txt

tim x
bob y
pete z
joe a

Goto notepad and paste this in: (save it as doit.bat)

for /f "delims=@" %i in (names.txt) do @echo call perms.bat "%i"

This line will call the perms.bat for every username found in names.txt

If you want to do all users in f:\users*.* and forgo excel all together do this: Instead of the for statement above. Goto notepad and paste this in:

for /D %i in ("f:\users\*.*") do call perms.bat "%~ni"

save it and name it doit.bat

open notepad and place your code slightly modified. Save and name it perms.bat

echo Y | takeown /F "F:\Users\%1" /R
icacls "F:\USERS\%1" /reset /T /C /Q
icacls "F:\USERS\%1" /inheritance:r /T /C /Q
icacls "F:\USERS\%1" /grant:r system:(oi)(ci)f /t /c /Q
icacls "F:\USERS\%1" /grant:r "Site admins":(oi)(ci)f /t /c /Q
icacls "F:\USERS\%1" /grant:r "Domain admins":(oi)(ci)f /t /c /Q
icacls "F:\USERS\%1" /grant:r "CREATOR OWNER":(OI)(CI)F /T /C /Q
icacls "F:\USERS\%1" /grant:r %1:(oi)(ci)f /t /c /Q
icacls "F:\USERS\%1" /remove:g "everyone" /T /C /Q
icacls "F:\USERS\%1" /remove:g "administrators" /T /C /Q
icacls "F:\USERS\%1" /remove Everyone /T /C /Q
icacls "F:\USERS\%1" /remove:g "COURTS\administrator.account" /T /C /Q
icacls "F:\USERS\%1" /remove "COURTS\administrator.account" /T /C /Q
icacls "F:\Users\%1" /setowner "COURTS\%1" /c /t /Q
icacls "F:\USERS\%1" /inheritance:e /T /C /Q
net share %1$ /delete
icacls "F:\USERS\%1" /remove:g "system" /T /C /Q
icacls "F:\USERS\%1" /remove "system" /T /C /Q
icacls "F:\USERS\%1" /remove:g "Site Admins" /T /C /Q
icacls "F:\USERS\%1" /remove "Site Admins" /T /C /Q
icacls "F:\USERS\%1" /remove:g "Domain Admins" /T /C /Q
icacls "F:\USERS\%1" /remove "Domain Admins" /T /C /Q
icacls "F:\USERS\%1" /remove:g "Creator Owner" /T /C /Q
icacls "F:\USERS\%1" /remove "Creator Owner" /T /C /Q

goto adminstrative command prompt.

If you want to execute this in real time do this:

type doit.bat

If you want to save the commands to a file:

for /f "delims=@" %i in (perms.bat) do echo echo %i ^>^>all.txt  >>txt.bat

backup perms.bat else where. Then rename txt.bat to perms.bat and execute doit.bat Then when you run doit.bat all the commands will appear in plain text in all.txt. You can then copy and paste the results into excel if you need to.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.