Follow via:
RSS
Email Alert
Question
0 Votes
+ -

Powershell Scripting for Home Drives

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?
Tags: windows
7th Feb

Answers (1)

0 Votes
+ -
See KB
See KB288991 for the permissions to set on your root folder - hopefully that will alleviate the need for the powershell script at all.

(Apologies if I have multi-posted - my posts aren't showing up).
9th Feb

Replies

Thanks gechurch, I will look into it.
MattCollinsUK 12th Feb
Answer the question
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.