permissions - Execute icacls in Powershell to grant access to a file share for domain computer -
permissions - Execute icacls in Powershell to grant access to a file share for domain computer -
i wonder how uses icacls within powershell script setting permissions on fileshare computeraccount e.g. domain\myserver$
this i'm trying:
$computeraccount = "domain\myserver$" $folder = "\\testserver\testshare\folder1" $rule = $computeraccount+':(m),(oi),(ci)' $resicacls = invoke-expression "icacls $folder /grant $rule" got error message: invoke-expression : @ line:1 char:83 + ... ant domain\myserver$:(m),(oi),(ci) + ~~ variable reference not valid. '$' not followed valid variable name character. consider using ${} delimit name. @ c:\binary\testacl.ps1:12 char:26 + $resicacls = invoke-expression "icacls $folder /grant $rule" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + categoryinfo : parsererror: (:) [invoke-expression], parseexception + fullyqualifiederrorid : invalidvariablereference,microsoft.powershell.commands.invokeexpressioncommand
i tried different variants of escaping $ found no solution. haves hint how this?
thanks!
try using phone call operator (&
) or cmd /c
instead of invoke-expression
:
& icacls $folder /grant $rule cmd /c icacls $folder /grant $rule
or utilize get-acl
/set-acl
changing permissions:
$permissions = 'modify' $inheritance = 'containerinherit, objectinherit' $acl = get-acl -path $folder $ace = new-object security.accesscontrol.filesystemaccessrule($computeraccount, $permissions, $inheritance, 'inheritonly', 'allow') $acl.addaccessrule($ace) set-acl -aclobject $acl -path $folder
powershell permissions share icacls
Comments
Post a Comment