如何调试"The term 'X' is not recognized as the name of a cmdlet, function, script file, or operable pr



代码:

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 = "MRGROUPro","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:scriptaclper.ps1:1 char:1
+ G$Folders = Get-childItem C:permissiontest
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (G$Folders:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

替换:

G$Folders = Get-childItem C:permissiontest

带有:

$Folders = Get-childItem C:permissiontest

这将消除这个错误

相关内容

最新更新