我想知道如何icacls在PowerShell脚本中用于为计算机帐户(例如Domain \ myServer $)设置文件共享的权限。
这是我正在尝试的:
$ComputerAccount = "domain\myServer$"
$Folder = "\\TestServer\TestShare\folder1"
$rule = $ComputerAccount+':(M),(OI),(CI)'
$resICacls = Invoke-Expression "icacls $folder /grant $rule"
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
调用表达式:在线:1字符:83
+ ... ant Domain \ myServer $ :( M),(OI),(CI)
+ ~~
变量引用无效。'$'后面没有有效的变量名
字符。考虑使用$ {}来分隔名称。
在c:\ Binary \ testacl.ps1:12 char:26
+ $ resICacls =调用表达式“ icacls $ folder / grant $ rule”
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo:ParserError:(:) [Invoke-Expression],ParseException
+ FullyQualifiedErrorId:InvalidVariableReference,Microsoft.PowerShell.Commands.InvokeExpressionCommand
我尝试了转义的不同变体,$但没有找到解决方案。任何人都有提示如何执行此操作?