SetAccessRule fails “The trust relationship between this workstation and the primary domain failed.”

I tried to change the access rights for a path and a file. But it gave me an error.

Exception calling “SetAccessRule” with “1” argument(s): “The trust relationship between this workstation and the primary domain failed.

The scripts I’ve used, were definitely working before, so the issue wasn’t with the script. I used these scripts, and only one of them failed:

$path = "path to change access rights for"
$acl = Get-Acl $path
$ar = New-Object system.security.accesscontrol.filesystemaccessrule("<domain>\Domain Users","Modify","Allow")
$acl.SetAccessRule($ar)
Set-Acl -Path $path $acl

$file = "full file path and name to the file to change access rights to"
$acl = Get-Acl $file
$ar = New-Object system.security.accesscontrol.filesystemaccessrule("Everyone","FullControl","Allow")
$acl.SetAccessRule($ar)
Set-Acl -Path $file $acl

It appeared that the one failed that’s one that adds the domain users group. I thought that because I just reverted a snapshot for this VM, that this might be the problem. According to the VM information, it was connected to the domain since the time the snapshot was made. So I restarted the server, which gave the server a ‘fresh’ connection to the domain. This solved the problem.

So it was just another case of “have you tried turning it off and on again?”.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s