Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Get-ACL and delete them all in Folder X

$
0
0

Hi everybody,

I´ve got a lil probleme with my script, I´m completet my userscript which creates almost automaticly new users and I´ve got a probleme with the HomeFolder rights.

here is the creating part:

 

New-AdUser -UserPrincipalName $UserDN@domain.org -SamAccountName $UserDN -Name $UserDN -GivenName $UserGN -Surname $UserSN -Enabled $True -Instance (Get-AdUser vorlage_$fachbereich) -AccountPassword (ConvertTo-SecureString "$PASS" -AsPlainText -force) -Path $OUZIFFER$Abteilung$OUPH$OUPath -PassThru -ChangePasswordAtLogon $true -PasswordNotRequired $false -ScriptPath "LogonSkript.cmd" -HomeDrive "G:" -HomeDirectory "$HomeDir" -Company "Company GmbH"

This creaton part does not create the homefolder (as I thought), I create the homefolder some steps later but the probleme is, when I start the script with my administrative account the homefolder which will be created later in the script, the Owner of the homefolder is the admin account.

So I thought, well just delete all existing rights on the folder an set them new with valid rights ... But it doesn´t work ... I used to work with the following commands ...

 

$UserDisplayname = "UserXXX"
$HomeDir = "\\server\home\"

$Acl = Get-Acl (Get-Item $HomeDir$UserDisplayname)
$Acl.Access | ForEach-Object {$Acl.RemoveAccessRule($_)}

After I started this part he just shows me true, true, true but still the wrong rights.

 

Can someone help me pls?

 

Many thanks

Best regards
Sempai0815


Viewing all articles
Browse latest Browse all 6937

Trending Articles