我们有一个服务器,其中包含所有用户的“我的文档”文件夹。一些文件夹所有者更改为管理员。我正在尝试设计一个 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
}