How to Get All Server Info from AD Without Timing Out?

0
2
Asked By CuriousCoder84 On

Hey everyone! I've been tasked with writing some PowerShell scripts to report on all the servers in our Active Directory domain. The goal is to format this information for upper management to review on SharePoint. I'm starting simple but have hit a snag right off the bat with gathering the data.

I began with a command I previously used for laptops but modified it for servers:

```powershell
Get-ADComputer -Filter "OperatingSystem -Like '*server*' -and Enabled -eq '$true'" -Property DNSHostName,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion | Select-Object DNSHostName,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion | Export-Csv "\fooServerReport - $((Get-Date).ToString("yyyy-MM-dd - HH_mm_ss")).csv"
```

Unfortunately, after about six minutes, I get an error saying "invalid enumeration context." I think this is happening because the command processes the first 256 objects and then fails when it waits for more. I've tried using variables to streamline things, like this:

```powershell
$servers = Get-ADComputer -Filter "OperatingSystem -Like '*server*' -and Enabled -eq '$true'" -Property DNSHostName,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion | Select-Object DNSHostName,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion | Export-Csv "\fooServerReport - $((Get-Date).ToString("yyyy-MM-dd - HH_mm_ss")).csv"
```

Still, I get stuck with just 256 objects. I've even tried breaking it down further into a full script with variables, but I'm still facing the same problem.

Has anyone run into this before? Any insights on how I can adjust my code to collect all the server information without timing out?

1 Answer

Answered By ServerWhisperer99 On

You might be hitting a limit with the number of objects being processed at once. Have you tried adjusting the page size to something smaller? You can use `-ResultPageSize 50` in your command to see if that helps you get more data without timing out.

CuriousCoder84 -

I did try changing the page size to 50 as you suggested, but it actually reduced the amount of data I received, dropping from 256 to about 150 objects.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.