Powershell Scripting for Home Drives

By MattCollinsUK ·
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) {
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")
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Administrators","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule("Domain Admins","FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$rule = New-Object System.Security.AccessControl.FileSystemAccessRule($userfolder.Name,"FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$acct=New-Object System.Security.Principal.NTAccount("nt_hld_admin",$userfolder.name)
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?

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Related Discussions

Related Forums