我想知道如何在powershell脚本中使用icacls来设置针对例如计算帐户的文件共享的权限。域\ myServer上$在Powershell中执行icacls以授予对域计算机的文件共享的访问权限
这就是我想:
$ComputerAccount = "domain\myServer$"
$Folder = "\\TestServer\TestShare\folder1"
$rule = $ComputerAccount+':(M),(OI),(CI)'
$resICacls = invoke-expression "icacls $folder /grant $rule"
I got this error message:
invoke-expression : At line:1 char:83
+ ... ant Domain\myServer$:(M),(OI),(CI)
+ ~~
Variable reference is not valid. '$' was not followed by a valid variable name character. Consider using ${} to delimit the name.
At 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
我试图逃避$的不同变体,但没有找到解决办法。 任何人都有一个提示如何做到这一点?
谢谢!