我应该使用Active Directory模块的cmdlet或的DirectoryServices .NET类模块、Directory、Active、NET

2023-09-08 13:05:59 作者:若再贱就再见

我有一个非常简单的问题。什么是更好地使用? AD模块(即获取-ADComputer)或的DirectoryServices尝试连接到AD拉的所有计算机,用户和组从域时.NET类。抑或是没有关系呢?

I have a really simple question. What is better to use? AD Module (ie. Get-ADComputer) or DirectoryServices .NET Class when trying to connect to AD and pull all computers, users, and groups from a Domain. Or does it not matter at all?

我判断上使用哪种方法,关键的因素是:

The key factors I judge on for which method to use are:

在哪种方法的脚本将运行得更快? 这使负荷更低的网络/ AD 在什么限制可能每个方法有哪些?

我知道AD模块仅安装在Win Server 2008 R2的默认和以后,所以这是一个不好的一面的旧服务器上明显给出,该模块是不是默认安装的。但在今天的世界上,真正应该不会有太大给出的问题不会有很多环境中的所有服务器超过2008 R2。

I know that the AD Module is only installed default on Win Server 2008 R2 and later, so that is a down side obviously given on an older server, the module isn't installed by default. But in today's world that really shouldn't be much of a problem given there aren't a lot of environments with all servers older than 2008 R2.

所有我想要做的是提取到.csv所有用户对象(和一些重要领域/属性),所有的计算机对象,并且所有组对象。所以基本上寻寻觅觅的广告对象,并通过每个结果行循环,然后保存为一个表导出为.csv。

All I am trying to do is extract to a .csv all User objects (and some important fields/attributes), all Computer objects, and all Group objects. So basically "searching" the AD objects and looping through each result row and then saving to a table to export to .csv.

推荐答案

ActiveDirectory中的cmdlet是的据的据的比使用System.DirectoryServices中更直观,但你可能会失去一些System.DirectoryServices中提供了控制。在大多数情况下,特别是对人的新的PowerShell,我会建议使用ActiveDirectory中的cmdlet

The ActiveDirectory cmdlets are far, far more intuitive than using System.DirectoryServices, however you may lose some of the control that System.DirectoryServices offers. For most cases, especially for people new to PowerShell, I would recommend using the ActiveDirectory cmdlets.

至于速度,像@sodawillow建议,可以测量每个的执行时间,然后使用最快的。我可以给你轶事,但他们不会被重新$ P $中每个人的经历psentative。

As far as speed, like @sodawillow suggested, you can measure the execution time of each and then use the fastest. I could give you anecdotes, but they would not be representative of everyone's experiences.