Solved

icacls, insert usename from a text file

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
A procedure for exporting installed hotfix details of remote computers using powershell
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
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…

734 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