这是我完成的脚本 Get-Module
$import_mods = Read-Host -Prompt 'do you NEED to load modules? "y" or "n" (Y)'
if ($import_mods -ine "n")
{
Import-Module ShareUtils, PowerShellAccessControl, Microsoft.PowerShell.Security
}
$newhome = "\\xray\HDs\"
out-file -filepath C:\test\acl.csv
Get-ChildItem -Path \\xray\hd -Directory | select PSChildName | Export-Csv C:\test\xray.csv
$csv1= import-csv -path C:\test\xray.csv
foreach ($user in $csv1)
{
$SAM = $user.PSChildName
$account = get-aduser -Identity $SAM -Properties *
$HomeDirectory = "$($newhome)$($Account.SamAccountName)"
$Acl = Get-Acl -Path $HomeDirectory -Filter *
if ($Acl.AccessToString -like "*everyone*")
{
Write-Output $user.pschildname | out-file -filepath C:\test\acl.csv -Append
$Ar = New-Object system.Security.AccessControl.FileSystemAccessRule($Account.SamAccountName, "modify", "ContainerInherit, ObjectInherit", "None", "Allow")
$Ar1 = New-Object system.Security.AccessControl.FileSystemAccessRule("yourdomain\Domain Admins", "full", "ContainerInherit, ObjectInherit", "None", "Allow")
$Ar2 = New-Object system.Security.AccessControl.FileSystemAccessRule("yourdomain\sadmins", "full", "ContainerInherit, ObjectInherit", "None", "Allow")
$Acl.setaccessrule($Ar2)
$Acl.setaccessrule($Ar1)
$Acl.Setaccessrule($Ar)
# next line disables inheritance and for my enviroment this is there "everyone" comes from
$Acl.SetAccessRuleProtection($true,$false)
Set-Acl $HomeDirectory $Acl
Write-Host $SAM "fixed user"
} else {Write-Host $SAM "good user"}
}
#3.0 rename & date acl.csv to record affected folders
$destpath = 'C:\test\'+"acl_"+(get-date -Format yyyyMMdd)+'.txt'
$sourcepath = 'C:\test\acl.csv'
Move-Item -Path $sourcepath -Destination $destpath
exit