Solved

icacls, insert usename from a text file

Posted on 2013-01-03
5
576 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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now