Getting a Full List of Servers from AD – Need Help with PowerShell

0
4
Asked By CuriousCat398 On

Hey folks, I'm working on a project where I need to generate a report of all the servers in our Active Directory domain using PowerShell. My goal is to format this data for SharePoint so that management can review it easily. I've started with a command to query server information, but I keep running into an error after six minutes saying 'invalid enumeration context.' It seems like the command is timing out after processing the first set of 256 objects. I've done some research and found that I should use variables to address this, but even when I try that, I still get the same outcome: a CSV file with only 256 entries. Below is the original command I'm using:

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"

I'd really appreciate any suggestions on how to debug this or alternative methods to get a complete list of server objects. Thanks!

2 Answers

Answered By ScriptNinja42 On

This might sound a bit basic, but how about using an ‘all’ filter and then filtering for servers afterward? Like so:

$all = Get-AdComputer -Filter *

$servers = $all | where-object {$_.OperatingSystem -like '*server*'}

I’ve got tons of AD objects and this method works pretty quickly for me!

Answered By TechGuru88 On

Have you checked if reducing the page size might help? You could try this command:

Get-ADComputer -Filter .. -Property .. -ResultPageSize 50

Adjusting the page size often helps mitigate timeout issues!

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.