Remotely setting ACL

Jelle Kamma (NL) 116 Reputation points
2021-10-13T12:15:45.357+00:00

Hi all,

I am trying to perfect my server installation script, which runs a bunch of tasks on every new machine. The script is runned under a local admin account which prompts for domain credentials. Everything is working great. I am trying to create a folder on our NAS and set modify permissions on it. however the variables are not working. I have tried to run all the commands using the ; separator. Below is part of the script that I am using.

$NASfolder is the path of the folder on the NAS
$cred is are the domain credentials. Can someone help me?

Invoke-Command -ComputerName server.domain.local -Credential $cred {New-Item -Path "P:\P" -Name "$Using:NASfolder" -ItemType "directory"}
Invoke-Command -ComputerName server.domain.local -Credential $cred {$Acl = Get-Acl P:\P\"$Using:NASfolder"}
Invoke-Command -ComputerName server.domain.local -Credential $cred {$Ar = New-Object system.Security.AccessControl.FileSystemAccessRule("Domain\User", "Modify", "ContainerInherit, ObjectInherit", "None", "Allow")}
Invoke-Command -ComputerName server.domain.local -Credential $cred {$Acl.Setaccessrule($Ar)}
Invoke-Command -ComputerName server.domain.local -Credential $cred {Set-Acl P:\P\"$Using:NASfolder" $Acl}

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,354 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Limitless Technology 39,336 Reputation points
    2021-10-14T19:06:11.27+00:00

    Hello @Jelle Kamma (NL)

    It seems that the main issue is that the account running the script has no Domain permissions (even if later you authenticate with Domain credentials. This scenario was discussed in the past in the next thread, I think you may find it useful to explain the behavior:

    https://social.technet.microsoft.com/Forums/en-US/65a476fe-61a5-4ff3-a7d1-53700a47784f/problem-with-setting-ntfs-permissions-using-systemsecurityaccesscontrolfilesystemaccessrule?forum=ITCG

    Hope this helps with your query,

    ------
    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments