windows - 脚本以集体更改文件夹权限
问题描述
我最近继承了一些混乱,我正在尝试编写解决方案的脚本……不幸的是,我不擅长编写脚本。有没有办法创建一个脚本,它将:
查找目录中的所有文件夹
按名称识别它们
将它们绑定到正确的用户(文件夹名称与 AD 用户名相同)
设置用户权限(匹配用户的完全控制 - 其他域用户没有权限)
我一直在尝试使用这样的东西......但我对变量如何工作的理解在这里低于标准。
$Acl = Get-Acl "C:\MyFolder"
$Ar = New-Object system.security.accesscontrol.filesystemaccessrule("$username","FullControl","Allow")
$Acl.SetAccessRule($Ar)
Set-Acl "C:\MyFolder" $Acl
如果有人愿意帮助我,将不胜感激。
解决方案
尝试利用 NTFS 模块。
文件系统安全 PowerShell 模块 4.2.3
允许使用 PowerShell 更轻松地管理文件和文件夹的权限
https://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85
#Get permissions from all files or folders in the current folder
dir | Get-NTFSAccess
#to read and also remove only the explicitly assigned ones
dir | Get-NTFSAccess -ExcludeInherited | Remove-NTFSAccess
#to backup permissions just pipe what Get-NTFSAccess returns to Export-Csv
dir | Get-NTFSAccess -ExcludeInherited | Export-Csv permissions.csv
#to retore the permissions pipe the imported data to Get-NTFSAccess
#As the imported data also contains the path you do not need to specify the item
Import-Csv .\permissions.csv | Get-NTFSAccess
https://www.powershellgallery.com/packages/NTFSSecurity/4.2.3
推荐阅读
- android - 如何从android中的外部存储上传文件?
- amazon-s3 - 如何使用 AWS Lambda [NodeJS] 将 base64 编码字符串作为图像上传到 S3
- spring - Spring Cloud Config 应用程序中 Bootstrap.properties 的位置
- laravel - 一种策略适用于多种模型
- python - 如何在 pygame 中制作形状/对象?
- windows - ipconfig 获取第一个mac地址
- rust - 是否有任何方便的方法来修改 Rust 结构的字段,同时克隆它而不不必要地克隆要修改的字段?
- javascript - 在函数中使用 Jest 测试 promise 的结果
- python - 如何有条件地为堆积条形图分配颜色?
- r - 如何使用荧光笔列在 ggplot 中映射动态颜色?