Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows Powershell将用户输入传递到icacls_Windows_Powershell - Fatal编程技术网

Windows Powershell将用户输入传递到icacls

Windows Powershell将用户输入传递到icacls,windows,powershell,Windows,Powershell,目前,我正在编写一个powershell脚本来自动执行一些安全措施,但遇到了一个小问题 icacls myDirectory /inheritance:r /grant:r 'Administrators:F' $myGroup + ':F' 将失败,因为$myGroup被附加到icacls调用上,并且无法正确地向这两个组添加权限。这是在Windows 7上,并且来自powershell的上下文。解析器将$myGroup+':F'视为三个单独的参数。您可以使用: "${myGroup}:F"

目前,我正在编写一个powershell脚本来自动执行一些安全措施,但遇到了一个小问题

icacls myDirectory /inheritance:r /grant:r 'Administrators:F' $myGroup + ':F'

将失败,因为$myGroup被附加到
icacls
调用上,并且无法正确地向这两个组添加权限。这是在Windows 7上,并且来自powershell的上下文。

解析器将
$myGroup+':F'
视为三个单独的参数。您可以使用:

"${myGroup}:F"


将此信息作为一个参数提供给解析器。

第二个参数有效,第一个参数失败。一旦你做了更改,我会接受这一点,因为答案看起来像
可以是变量名的合法部分,所以你必须使用
{
}
.Hmm来描述字符串的变量名部分。不能将
放在变量名中。想知道为什么解析器不能解决这个问题,并且不需要花括号?
($myGroup + ':F')