代码:如何调试“术语”X“不被识别为cmdlet,函数,脚本文件或可操作程序的名称”?
G$Folders = Get-childItem C:\permissiontest\
$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit -bor [System.Security.AccessControl.InheritanceFlags]::ObjectInherit
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly
$objType = [System.Security.AccessControl.AccessControlType]::Allow
foreach ($TempFolder in $Folders)
{
echo "Loop Iteration"
$Folder = $TempFolder.FullName
$acl = Get-Acl $Folder
$permission = "MRGROUP\ro","Read", $InheritanceFlag, $PropagationFlag, $objType
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule $permission
$acl.SetAccessRule($accessRule)
Set-Acl $Folder $acl
}
错误:
G$Folders : The term 'G$Folders' 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.
At C:\script\aclper.ps1:1 char:1
+ G$Folders = Get-childItem C:\permissiontest\
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (G$Folders:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
那么'G $文件夹'不是一个命令。你期望'G $ name'会做什么?大概是,摆脱G并在第一行使它成为'$ Folders ='。 – TessellatingHeckler
欢迎来到StackOverflow。如果你想让人们帮忙,你至少应该在你的问题上付出一些努力。你从字面上甩掉了脚本和错误,没有上下文。你甚至没有花时间来格式化(我只是为你做的)。 –