Author Posts

September 6, 2018 at 2:34 pm

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) }

}

 

September 6, 2018 at 3:19 pm

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.

September 6, 2018 at 3:30 pm

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) }

}

September 6, 2018 at 3:36 pm

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) }

}

September 6, 2018 at 4:18 pm

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.

September 6, 2018 at 4:24 pm

I use the following options

$Action = "/Remove"

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

$Opt = "/RO"