Solved

Adding NTFS Permissions for files that a different user has ownership of

Posted on 2014-12-09
6
110 Views
Last Modified: 2014-12-10
I'm looking for a script that will add user NTFS permissions whenever a different user has ownership of files located in a specific directory.

For example:

For each file in directory J:\folder that user "Domain\UserName" is the owner of, add user "Domain\NewUser" with read/write permission.

I'm not sure how much it matters, but the server is 2003 R2.
0
Comment
Question by:CoreyN
[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
6 Comments
 
LVL 4

Expert Comment

by:akalyan911
ID: 40488921
I think, creating the group policy for login script will work as you expected..

create the group policy for particular OU.. New Group Policy --> Under User configuration --> Drive Mapping --> \\Server Name\Sharedrive\Label As\

It will allow whomever is logged in having read & right permissions.. for that particular user..
0
 
LVL 1

Author Comment

by:CoreyN
ID: 40489166
Hi Akalyan911,

I'm only looking to have the permissions changes on a specific folder on a specific share.

Does Group Policy restrict itself to a specific folder of a specific share?
0
 
LVL 24

Accepted Solution

by:
NVIT earned 500 total points
ID: 40490233
Note:
1. Please test an isolated folder first. I haven't tested the ICACLS line
2. To run it for real, remove the ECHO in front of icacls
3. DIR output to CurrOwners.txt is from Windows 2008 CMD prompt

@echo off
cls
set SrchFile=CurrOwners.txt
REM Current owner:
dir /a-d /q /x J:\folder >%SrchFile%

set SrchFile=CurrOwners.txt
set GrantChk=Domain\UserName
set GrantTo=Domain\NewUser

for /f "usebackq skip=7 tokens=5* delims= " %%a in (%SrchFile%) do (call :DoIt "%%a" "%%b")
goto :eof

:DoIt
echo.
set owner=%1
set fn=%2
if %fn%=="" goto :eof
echo owner=%owner%
echo fn=%fn%
if /i %owner%=="%GrantChk%" (
  ECHO icacls %fn% /grant %GrantTo%:^(R,W^)
)
goto :eof

Open in new window

0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 1

Author Comment

by:CoreyN
ID: 40491357
Hi NewVillageIT

Thanks for the batch file. It works!  The only caveat, is the batch needs to be run in the directory were I want the files to be changed are located.  This is because the icacls command is only being passed the file name and not the full path.

When running from the correct directory; it works great!

Many Thanks!
0
 
LVL 1

Author Closing Comment

by:CoreyN
ID: 40491360
Thanks for the quick response!
0
 
LVL 24

Expert Comment

by:NVIT
ID: 40492374
You're welcome. Glad to help.

Re: the "...only being passed the file name and not the full path", try change the DoIt section like:
:DoIt
echo.
set owner=%1
set fn=%2
set ffn=%~f2
if %fn%=="" goto :eof
echo owner=%owner%
echo fn=%fn%
if /i %owner%=="%GrantChk%" (
  ECHO icacls "%ffn%" /grant %GrantTo%:^(R,W^)
)
goto :eof

Open in new window

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

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).
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…

726 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