I want to be able to set the IIS account for new websites to have modify permissions. I have the following script:
function Set-ModifyPermission ($directory, $username, $domain = 'IIS APPPOOL') {
$inherit = [system.security.accesscontrol.InheritanceFlags]"ContainerInherit, ObjectInherit"
$propagation = [system.security.accesscontrol.PropagationFlags]"None"
$acl = Get-Acl $directory
$user = New-Object System.Security.Principal.NTAccount($domain, $username )
$accessrule = New-Object system.security.AccessControl.FileSystemAccessRule($user, "Modify", $inherit, $propagation, "Allow")
$acl.AddAccessRule($accessrule)
set-acl -aclobject $acl $directory
}
However, when I run it, I get errors like this:
Set-Acl : The trust relationship between this workstation and the primary domain failed.
I think this is because IIS APPPOOL
isn't a real domain, but is a weird prefix on a kind-of-fake account. Is there a correct way to refer to that account so that I can make this work?