Constrained Language Mode issue

Welcome Forums General PowerShell Q&A Constrained Language Mode issue

This topic contains 1 reply, has 2 voices, and was last updated by

Senior Moderator
10 months, 4 weeks ago.

  • Author
  • #119491

    Topics: 49
    Replies: 51
    Points: 268
    Rank: 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: 1042
    Points: 3,450
    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

The topic ‘Constrained Language Mode issue’ is closed to new replies.