Constrained Language Mode issue

Welcome Forums General PowerShell Q&A Constrained Language Mode issue

Viewing 1 reply thread
  • Author
    • #119491
      Topics: 66
      Replies: 71
      Points: 510
      Rank: Major Contributor

      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.



      $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

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

      Example OutPut

      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: (:) [], RuntimeException
      + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage


    • #119530
      Senior Moderator
      Topics: 8
      Replies: 1215
      Points: 4,334
      Helping Hand
      Rank: Community Hero

      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
Viewing 1 reply thread
  • The topic ‘Constrained Language Mode issue’ is closed to new replies.