mkbell
mkbell

Reputation: 1

How to debug "The term 'X' is not recognized as the name of a cmdlet, function, script file, or operable program"?

Code:

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
} 

Error:

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

Upvotes: 0

Views: 1000

Answers (1)

BenH
BenH

Reputation: 10044

Replace:

G$Folders = Get-childItem C:\permissiontest\

with:

$Folders = Get-childItem C:\permissiontest\

That will get rid of this error

Upvotes: 1

Related Questions