Solved

icacls, insert usename from a text file

Posted on 2013-01-03
5
591 Views
Last Modified: 2013-01-03
icacls.exe \\49test-DATA\Backups$\staff\$_\Backups /grant 'test\$_:(OI)(CI)(M)'
icacls.exe \\49test-DATA\Users$\staff\$_\Data /grant 'test\$_:(OI)(CI)(M)'


I'm using this in the script below to assign permissions to a folder.  I don't have great knowledge of PS or scripting but I'm learning. I wrote out all the individual lines so i can understand. I used the $_ variable in the new-item expression to pull usernames from a text file. This parts works and the folders are created for the user in the txt file.
It doesn't work in the icacls line. I would like it to pull from the same exact txt file I used to create the folders.

Get-Content .\users.txt | ForEach-Object {
new-item \\49test-DATA\Backups$\staff\$_\Backups -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Desktop -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Favorites -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Documents -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Music -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Pictures -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Videos -itemtype directory
icacls.exe \\49test-DATA\Backups$\staff\$_\Backups /grant 'test\$_:(OI)(CI)(M)'
icacls.exe \\49test-DATA\Users$\staff\$_\Data /grant 'test\$_:(OI)(CI)(M)'
0
Comment
Question by:cs2009
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 38741691
Try this..
Get-Content C:users.txt | ForEach-Object {
new-item \\49test-DATA\Backups$\staff\$_\Backups -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Desktop -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Favorites -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Documents -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Music -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Pictures -itemtype directory
new-item \\49test-DATA\Users$\staff\$_\Data\Videos -itemtype directory
cmd /c "icacls.exe \\49test-DATA\Backups$\staff\$_\Backups /grant "test\$_":(OI)(CI)(M)"
cmd /c "icacls.exe \\49test-DATA\Users$\staff\$_\Data /grant "test\$_":(OI)(CI)(M)"
}

Open in new window

0
 

Author Comment

by:cs2009
ID: 38741778
Beautiful!!!

So I needed quotes around the key strings?
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38741794
Yes.. and if you use single quotes then it wont expand the variable..
0
 

Author Comment

by:cs2009
ID: 38741798
excellent, thanks so much.
0
 
LVL 40

Expert Comment

by:Subsun
ID: 38741811
There are other methods to run command line tools like icacls.exe. You can refer the following article, If you are interested..

http://blogs.technet.com/b/josebda/archive/2012/03/03/using-windows-powershell-to-run-old-command-line-tools-and-their-weirdest-parameters.aspx
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb entity bean example 2 17
MinPasswordAge for a single user in a Windows 2012 R2 domain 6 24
how to include conditional log rotate in liunx. 17 41
learn programming 8 43
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question