Solved

icacls, insert usename from a text file

Posted on 2013-01-03
5
605 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Ready to trade in that old firewall?

Whether you need to trade-up to a shiny new Firebox or just ready to upgrade from whatever appliance you're using now, WatchGuard has the right appliance for you! Find your perfect Firebox today with appliance sizing tool!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Make the most of your online learning experience.
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

615 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