AsBuiltReport / AsBuiltReport.Microsoft.AD

Repository for AsBuiltReport Microsoft Active Directory module
https://techmyth.blog/posts/homelab-ad-doc-using-asbuiltreport/
MIT License
63 stars 18 forks source link

Error while running the script #98

Closed jpcapone closed 1 year ago

jpcapone commented 1 year ago

Bug description

While running any cmdlet to generate the AD report I get the error: the server has returned the following error invalid enumeration context while running Get-Aduser

Command-line input

New-AsBuiltReport -Report Microsoft.AD -Target 'admin-dc-01v.contoso.local' -Username 'administrator@contoso.local' -Password 'P@ssw0rd' -Format Html,Word -OutputFolderPath 'C:\Users\Jon\Documents' -Timestamp

Steps to reproduce

The error occurs after running New-AsBuiltReport -Report Microsoft.AD -Target 'admin-dc-01v.contoso.local' -Username 'administrator@contoso.local' -Password 'P@ssw0rd' -Format Html,Word -OutputFolderPath 'C:\Users\Jon\Documents' -Timestamp

Expected behaviour

Script should run to completion with no errors.

Screenshots

No response

Operating System

Windows Server 2019

PowerShell Version

5.1.22621.963

PowerShell Modules


Name                       Version
----                       -------
AsBuiltReport.Core         1.3.0  
AsBuiltReport.Microsoft.AD 0.7.12 
PScribo                    0.10.0 
PScriboCharts              0.9.0  
PSPKI                      3.7.2 

Additional Context

The script does complete after the error occurs. i believe it is caused by the number of users theGet-ADUsercmdlet has to parse which is roughly 265000 users. I ran another script to validate the user object count and found that the difference in the value was neglible but very close.

Before submitting

rebelinux commented 1 year ago

Hello:

can you tell me which specific table in the report you are referring to?

thanks!

jpcapone commented 1 year ago

The Users Object Count Pie Chart and Table - 1.2.1.3.3.

jpcapone commented 1 year ago

Heres a screenshot: image

rebelinux commented 1 year ago

Thanks for the info,

could you share with me the other script you run to compare the numbers?

jpcapone commented 1 year ago

I kept it simple (Get-ADUser -Filter *).Count

rebelinux commented 1 year ago

I have done a test on a larger environment than yours and I can't reproduce the error. However, I made some changes in the code to see if it can help to avoid this type of error.

PS C:\Users\jocolon> (Get-ADUser -Filter *).Count
278838
PS C:\Users\jocolon> (Get-ADGroup -Filter *).Count
14693
PS C:\Users\jocolon> (Get-ADComputer -Filter *).Count
57150

Another question is if you executed the command with the EnableHealthCheck option?

jpcapone commented 1 year ago

I have gotten the error with and without the EnableHealthCheck option. Its weird that you didn't get the same error. If I update my module will the changes you made be downloaded?

rebelinux commented 1 year ago

I analyzed this situation in depth and was able to recreate the issue. I found that the error is caused when the powershell process consumes too much memory caused by the excessive amount of objects it has to process.

As much as I have improved the code I have not found a way through powershell to correct the error because most of the time it works but in certain occasions the error is displayed.

jpcapone commented 1 year ago

I greatly appreciate your efforts. If you need someone to help test any changes please let me know.

rebelinux commented 1 year ago

I greatly appreciate your efforts. If you need someone to help test any changes please let me know.

v0.7.13 is out with a lot of changes!

jpcapone commented 1 year ago

I greatly appreciate your efforts. If you need someone to help test any changes please let me know.

I attempted to update the cert but i am getting the error in the screenshot. I know I can skip publisher and force the install but, hmmmm......

image

rebelinux commented 1 year ago

I updated PSPKI to version 4.0.0.0 with no problems. Additionally I ran the report with that version and didn't encounter any issues.

jpcapone commented 1 year ago

I updated PSPKI to version 4.0.0.0 with no problems. Additionally I ran the report with that version and didn't encounter any issues.

I got the same certificate error when I attempted to run the PSPKI update as well. You didn't get that error for either?

rebelinux commented 1 year ago

When I did the update on one of my computers I did not get that error.

I have seen this error in other powershell modules and it is a known PowerShellGet issue.

https://github.com/PowerShell/PowerShellGetv2/issues/650

The use of the -SkipPublisherCheck parameter solves the problem.

However, I will modify the README file to include a comment on this possible issue. Thank you.

rebelinux commented 1 year ago

Any opinion on this matter?