call depth overflow error

Welcome Forums General PowerShell Q&A call depth overflow error

This topic contains 5 replies, has 3 voices, and was last updated by

MvW
 
Participant
3 months, 1 week ago.

  • Author
    Posts
  • #111109
    MvW

    Participant
    Points: 1
    Rank: Member

    Hi,
    The script below causes a failed due to call depth overflow with Powershell v5

    How can I fix this call depth overflow problem?
    function RecurseFolder

    {

    $f = $fold

    #  If ($Show) { write-output $f }

    If ($OU) { $ListFold = get-childitem AD:$f -force | Where-Object { ($_.ObjectClass -like "container") -or ($_.ObjectClass -like "OrganizationalUnit") } }

    Else

    {

    try

    {

    $ListFold = get-childitem AD:$f -force -ErrorAction SilentlyContinue

    }

    catch

    {

    Write2Log  "ERROR: because it does not exist.  $f"  -LogType 'Information'

    }

     

    }

    foreach ($e in $ListFold)

    {

    $FD = $e.Distinguishedname

    # write-output $FD

    RemovePerms $FD

    }

    #  $ListFold=get-childitem AD:$f -force

    # |where { ($_.ObjectClass -like "container")-or($_.ObjectClass -like "OrganizationalUnit") }

    foreach ($e in $ListFold) { RecurseFolder($e.Distinguishedname) }

    }

     

  • #111110

    Participant
    Points: 894
    Helping Hand
    Rank: Major Contributor

    Can you explain on what are you trying to do ? and
    I request you to format the code as it is difficult to understand in normal font, below link will help you.

  • #111112
    MvW

    Participant
    Points: 1
    Rank: Member

    To remove all unknown SIDs in Active Directory domains!
    https://gallery.technet.microsoft.com/How-to-remove-all-unknown-9d594f3a/view/Discussions

    function RecurseFolder
    {
    $f = $fold
    # If ($Show) { write-output $f }
    If ($OU) { $ListFold = get-childitem AD:$f -force | Where-Object { ($_.ObjectClass -like "container") -or ($_.ObjectClass -like "OrganizationalUnit") } }
    Else
    {
    try
    {
    $ListFold = get-childitem AD:$f -force -ErrorAction SilentlyContinue
    }
    catch
    {
    Write2Log "ERROR: because it does not exist. $f" -LogType 'Information'
    }
    }
    foreach ($e in $ListFold)
    {
    $FD = $e.Distinguishedname
    # write-output $FD
    RemovePerms $FD
    }
    # $ListFold=get-childitem AD:$f -force
    # |where { ($_.ObjectClass -like "container")-or($_.ObjectClass -like "OrganizationalUnit") }
    foreach ($e in $ListFold) { RecurseFolder($e.Distinguishedname) }

    }

  • #111113
    MvW

    Participant
    Points: 1
    Rank: Member

    To remove all unknown SIDs in Active Directory domains!
    https://gallery.technet.microsoft.com/How-to-remove-all-unknown-9d594f3a/view/Discussions

    
    function RecurseFolder
    {
    $f = $fold
    # If ($Show) { write-output $f }
    If ($OU) { $ListFold = get-childitem AD:$f -force | Where-Object { ($_.ObjectClass -like "container") -or ($_.ObjectClass -like "OrganizationalUnit") } }
    Else
    {
    try
    {
    $ListFold = get-childitem AD:$f -force -ErrorAction SilentlyContinue
    }
    catch
    {
    Write2Log "ERROR: because it does not exist. $f" -LogType 'Information'
    }
    }
    foreach ($e in $ListFold)
    {
    $FD = $e.Distinguishedname
    # write-output $FD
    RemovePerms $FD
    }
    # $ListFold=get-childitem AD:$f -force
    # |where { ($_.ObjectClass -like "container")-or($_.ObjectClass -like "OrganizationalUnit") }
    foreach ($e in $ListFold) { RecurseFolder($e.Distinguishedname) }
    
    }
    
    
  • #111115

    Participant
    Points: 27
    Rank: Member

    Ok, so based on the script from the gallery, how are you running the script?  What switches are you using when you run the script?

    The RecurseFolder function may have been caught in a loop, which can cause the overflow error.

  • #111116
    MvW

    Participant
    Points: 1
    Rank: Member

    I use the following options

    $Action = "/Remove"

    $folder = "DC=xx, DC=xx, DC=xx"

    $Opt = "/RO"

The topic ‘call depth overflow error’ is closed to new replies.