Hello All,
I have a power shell script which sets the correct permissions on a users home drive. the script works perfectly for all folders, apart from when a folder has v2 appended to it.
For example:
MDCollins (works fine)
MDCollins.V2 (errors)
Below i have pasted the script i am using
Import-Module ActiveDirectory
$rootfolder = Get-ChildItem -Path \\mt02\test\profiles\
foreach ($userfolder in $rootfolder) {
$userfolder.FullName
If (get-aduser “$userfolder”) {
Get-Acl $userfolder.FullName | Format-List
$acl = Get-Acl $userfolder.FullName
$acl.SetAccessRuleProtection($True, $False)
$acl.Access | ForEach-Object{ $acl.RemoveAccessRule($_) }
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(“Everyone”,”FullControl”, “ContainerInherit, ObjectInherit”, “None”, “Allow”)
$acl.RemoveAccessRuleAll($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(“Administrators”,”FullControl”, “ContainerInherit, ObjectInherit”, “None”, “Allow”)
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule(“Domain Admins”,”FullControl”, “ContainerInherit, ObjectInherit”, “None”, “Allow”)
$acl.AddAccessRule($rule)
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userfolder.Name,”FullControl”, “ContainerInherit, ObjectInherit”, “None”, “Allow”)
$acl.AddAccessRule($rule)
$acct=New-Object System.Security.Principal.NTAccount(“nt_hld_admin”,$userfolder.name)
$acl.SetOwner($acct)
Set-Acl $userfolder.FullName $acl
Get-Acl $userfolder.FullName | Format-List
}
}
When i run the script, it searches active directory for (for example mdcollins.v2) and obviously no object exists for that, which is why it errors.
What i want to script to do, is to once it has found a folder without v2 in it, search for folders the same but with the .v2 added, then set the same permissions.
Hope this makes sense.
Any Ideas?