Solved

icacls, insert usename from a text file

Posted on 2013-01-03
5
564 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
Comment Utility
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
Comment Utility
Beautiful!!!

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

Expert Comment

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

Author Comment

by:cs2009
Comment Utility
excellent, thanks so much.
0
 
LVL 40

Expert Comment

by:Subsun
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Set OWA language and time zone in Exchange for individuals, all users or per database.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

771 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

9 Experts available now in Live!

Get 1:1 Help Now