![如何在 icalcs PS 命令中正确包含 $ 变量](https://linux22.com/image/1520451/%E5%A6%82%E4%BD%95%E5%9C%A8%20icalcs%20PS%20%E5%91%BD%E4%BB%A4%E4%B8%AD%E6%AD%A3%E7%A1%AE%E5%8C%85%E5%90%AB%20%24%20%E5%8F%98%E9%87%8F.png)
我正在尝试通过运行来更改用户主文件夹的权限
icacls $folder /grant corp.commonwealth.com\"$folder":(OI)(CI)F /t
其中 $folder 是此人的用户名。
我一直收到错误
OI : The term 'OI' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
在仍具有 :(OI)(CI)F 选项的同时包含 $folder 变量的最佳方法是什么?
谢谢!
答案1
通过执行以下操作可以解决此问题:
$username = get-content T:\userlist.txt
$icacls = "C:\Windows\system32\icacls.exe"
&$icacls $username /grant domain\"$username"":(OI)(CI)F /t"