This script will search the selected folder then active directory and apply NTFS permissions to the same user as the folders name. You only have to modify the below commands:
"SELECT samaccountname FROM 'LDAP://DC=DOMAIN,DC=NAME' "
aparentfolder = "F:\FOLDER\LOCATION\MATCH\USERNAME"
objShell.Run "c:\winnt\system32\cacls.exe (Change to where cacls.exe is located)
Save the file as "Permissionsfix.vbs"
on error resume next
aparentfolder = "F:\FOLDER\LOCATION"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(aparentfolder)
Set objShell = wscript.CreateObject("WScript.Shell")
Set colSubfolders = objFolder.Subfolders
For Each objsubfolder In colSubfolders
'findUser (objsubfolder.Name)
userpathv = aparentfolder & "\" & objsubfolder.Name
'wscript.echo userpathv
objShell.Run "c:\winnt\system32\cacls.exe " & userpathv & " /T /E /G " & objsubfolder.Name & ":c"
wscript.Sleep 1500
Next
wscript.echo "Job Done"
wscript.quit
Function findUser(usernametofind)
nameval = 0
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"SELECT samaccountname FROM 'LDAP://DC=domain,DC=Name' " _
& "WHERE object'user'"
objCommand.Properties("Page Size") = 2000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
If usernametofind = objRecordSet.Fields("samaccountname").Value Then
nameval = 1
Else
End If
objRecordSet.MoveNext
Loop
if nameval <> 1 then wscript.echo usernametofind & " account does not exist in domain - delete folder"
End Function