【发布时间】:2018-04-03 14:54:16
【问题描述】:
我们有一个服务器,其中包含所有用户的“我的文档”文件夹。一些文件夹所有者更改为管理员。我正在尝试设计一个 PowerShell 脚本,该脚本将转到每个用户的根我的文档文件夹,并将用户应用为其中所有子文件夹和文件的所有者。这可能吗?
我从以前的脚本中获得了以下内容,该脚本试图将用户设置为每个我的文档根文件夹的完全权限:
$FolderPath = "E:\mydocuredir\"
$MyDocsMain = Get-ChildItem -Path $FolderPath -Directory
Get-ChildItem -Path $FolderPath -Directory | ForEach-Object{
$HomeFolders = Get-ChildItem $FolderPath $_.Name -Directory
$Path = $HomeFolders.FullName
$Acl = (Get-Item $Path).GetAccessControl('Access')
$Username = $_.Name
$Ar = New-Object System.Security.AccessControl.FileSystemAccessRule($Username, 'FullControl', 'ObjectInherit', 'InheritOnly', 'Allow')
$Acl.SetAccessRule($Ar)
Set-Acl -path $Path -AclObject $Acl
}
【问题讨论】:
-
my docs 文件夹的结构是什么,类似于
E:\mydocuredir\username\?folder? -
是的。 mydocuredir 后面的用户名文件夹,那么就是他们的文件和文件夹。
标签: powershell windows-server windows-networking