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

 
Participant
1 month, 1 week ago.

  • Author
    Posts
  • #119491

    Participant
    Points: 29
    Rank: Member

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

     

  • #119530

    Participant
    Points: 819
    Helping Hand
    Rank: Major Contributor

    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
    

You must be logged in to reply to this topic.