• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 113
  • Last Modified:

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

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
CoreyN
Asked:
CoreyN
  • 3
  • 2
1 Solution
 
akalyan911Commented:
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
 
CoreyNAuthor Commented:
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
 
NVITCommented:
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
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
CoreyNAuthor Commented:
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
 
CoreyNAuthor Commented:
Thanks for the quick response!
0
 
NVITCommented:
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

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now