AD域的计算机用户自主控制文件夹权限

Z先森 2021-03-31 PM 1487℃ 0条

基于对windows文件共享的权限精细控制需求,编了一个小脚本
可以实现加了AD域的计算机用户自主控制文件夹权限

  • 实现功能:1、只有自己可编辑;2、别人只读;3、别人可修改不可删除;4、小组成员有所有权限
@echo off
echo .   把文件或文件夹拖到这个bat上面使用

for /F %%i in ('whoami /upn') do (set user=%%i)
for /F %%x in ('whoami /fqdn') do (set team=%%x)
for /F "tokens=1,* delims=," %%m in ("%team%") do (set team=%%n)
for /F "tokens=1,* delims=," %%a in ("%team%") do (set team=%%a)

set team=%team:[email protected]

set dir=%1

dir /ad "%dir%" >nul 2>nul && set isdir=(OI)(CI) || set isdir=

goto choose

:choose
echo %team% %user% %dir% %isdir%
echo.        
echo.        1、只有自己可以编辑的权限
echo.        
echo.        2、别人看见的只读权限
echo.        
echo.        3、别人可修改不可删除权限
echo.        
echo.        4、小组有所有权限
echo.        
echo.        请输入选择项目的序号:
set /p  ID=
if "%id%"=="1"  goto urwx
if "%id%"=="2"  goto or
if "%id%"=="3"  goto orw
if "%id%"=="4"  goto orwx

:urwx
echo 先禁用继承
icacls %dir% /inheritance:d
echo.        
echo 添加用户有所有权限
icacls %dir% /grant:r %user%:%isdir%(F)
echo.        
echo 移除组的权限
icacls %dir% /remove:g %team%
echo.        
goto getacl

:or
echo 先禁用继承
icacls %dir% /inheritance:d
echo.        
echo 添加用户有所有权限
icacls %dir% /grant:r %user%:%isdir%(F)
echo.        
echo 移除组的权限
icacls %dir% /remove:g %team%
echo.        
echo 设置组只读
icacls %dir% /grant:r %team%:%isdir%(RX)
echo.        
goto getacl

:orw
echo 先禁用继承
icacls %dir% /inheritance:d
echo.        
echo 添加用户有所有权限
icacls %dir% /grant:r %user%:%isdir%(F)
echo.        
echo 移除组的权限
icacls %dir% /remove:g %team%
echo.        
echo 设置组
icacls %dir% /grant:r %team%:%isdir%(RX,GW)
echo.        
goto getacl

:orwx
echo 先禁用继承
icacls %dir% /inheritance:d
echo.        
echo 移除组的权限
icacls %dir% /remove:g %team%
echo.        
echo 设置组
icacls %dir% /grant:r %team%:%isdir%(F)
echo.        
goto getacl

:getacl
icacls %dir%

pause
标签: none

如无特殊说明,本博所有文章均为博主原创。

评论啦~