Constrained Language Mode issue

My objective is to remove all ‘old’ account names on Profile shares since the domain is going away. These shares reside on a clustered file share environment and I need to run through each profile to remove any account with the ‘mmsasp’ domain in it.

The language mode is constrained language mode and I can 't seem to find a way around it.

 

Code

$Profiles = Get-ChildItem D:\Profiles foreach ($Profile in $Profiles){

$acl = get-acl $Profile.FullName
$rules = $acl.Access | Where-Object {$_.identityreference -like “mmsasp”}

foreach ($rule in $rules ){
write-host $Profile.FullName -ForegroundColor Yellow
$rule
$acl.RemoveAccessRule($rule)

set-acl -Path $Profile.FullName -AclObject $acl
}


Example OutPut

D:\Profiles\easystreet FileSystemRights : FullControl AccessControlType : Allow IdentityReference : MMSASP\Domain Admins IsInherited : True InheritanceFlags : ContainerInherit, ObjectInherit PropagationFlags : None

Cannot invoke method. Method invocation is supported only on core types in this language mode.
At line:11 char:9

  • $acl.RemoveAccessRule($rule)
  • CategoryInfo : InvalidOperation: (:slight_smile: [], RuntimeException
  • FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage

 

Yes this is constrained language mode and this action is not supported there. You can workaround this by calling the script in a new exe without constrained language mode.

PowerShell.exe -f c:\yourscript.ps1