Hi Guys,
I’m running into a problem. With the code below I’m creating a new user, creating a new home directory and setting the correct ACL for the user.
When the script is done, the user is created, the folder is created and I can see the user having full permissions on the folder. However the user is not able to access the folder.
When I remove the permissions through the gui and apply them again, it does work.
Does any of you have any ideas? Thanks in advance.
Below is not the complete code, but I think it should be sufficient to identify the problem.
Function Create-User
{
param ($username = $x_username.Text,
$password = $x_password.Text,
$firstname = $x_firstname.Text,
$lastname = $x_lastname.Text,
$administratie = $x_administratie.Text,
$company = $x_company.Text,
$radar = $x_radar.Text
);
$error.clear()
try { $userexists = Get-ADUser -Identity $username }
catch
{
$password = ConvertTo-SecureString $password -AsPlainText -Force
$HomeDirectory = "\\servername\HomeFolderName\$username"
NEW-ITEM –path $HomeDirectory -type directory -force
Set-ItemProperty $HomeDirectory -name IsReadOnly -value $false
New-ADUser -Name $username -SamAccountName $username -Path "OU=***,OU=***,DC=***,DC=***" -GivenName $firstname -Surname $lastname -DisplayName "$firstname $lastname" -AccountPassword $password -Enabled $true -PasswordNeverExpires $true -Description "$administratie - $radar" -Company $company -HomeDrive "H:" -HomeDirectory $HomeDirectory
$Acl = Get-Acl $HomeDirectory
$Ar = New-Object system.Security.AccessControl.FileSystemAccessRule($username, "FullControl", "ContainerInherit, ObjectInherit", "None", "Allow")
$Acl.Setaccessrule($Ar)
Set-Acl $HomeFolder $Acl