定位特定服务器时,如何使Get-ADUser更好地执行? [英] How to get Get-ADUser to perform better when targeting a specific server?

查看:86
本文介绍了定位特定服务器时,如何使Get-ADUser更好地执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从域中的所有用户那里获取属性数组。如果未指定特定的域控制器,查询将在不到一秒钟的时间内返回有效结果。如果我指定了目标控制器,即使在最接近的域控制器上,返回结果也需要18秒。唯一的不同是,我使用 -Server $ serverName 定位了服务器。

I am obtaining an array of properties from all users in the domain. If I do not specify a specific domain controller the query returns valid results in less than one second. If I specify a target controller, even on my closest domain controller, the result takes 18 seconds to return. The only difference is that I have targeted a server using -Server $serverName.

如何获得相同的结果指定服务器时的性能?这是由用户界面驱动的,因此在数据更改后要等待18秒(最短)是很长的时间。在函数 $ serverName 中提取存储的字符串值,因此不执行任何处理。

How do I get the same performance while specifying a server? This is user-interface driven so waiting 18 seconds (minimum) is a long time to wait after data changes. In the function $serverName pulls a stored string value, so no processing is performed.

此外,是否有办法知道哪个服务器 Get-ADuser 撤消了它

Also, is there a way to know which server Get-ADuser pulled its information from if I don’t specify a server?


连接服务器:* [未指定服务器] >>经过时间HH:MM :SS =
00:00:00.9451947

Connected-Server: * [Server not specified] >> Elapsed time HH:MM:SS = 00:00:00.9451947

已连接服务器:SERVER1 >>经过时间HH:MM:SS = 00:00:42.8815911

Connected-Server: SERVER1 >> Elapsed time HH:MM:SS = 00:00:42.8815911

连接服务器:SERVER2 >>经过时间HH:MM:SS = 00:00:39.8800249

Connected-Server: SERVER2 >> Elapsed time HH:MM:SS = 00:00:39.8800249

连接服务器:SERVER3 >>经过时间HH:MM:SS = 00:00:18.1686541

Connected-Server: SERVER3 >> Elapsed time HH:MM:SS = 00:00:18.1686541



Function Get-TargetObjectList( $targetSearchBase )
{
    $propertyList  = "Enabled", "DistinguishedName", "Name", "department", "givenName","sn","displayName","CanonicalName", "Description"
    $serverName    = Get-CurrentDC  # which domain controller name did the user choose from the drop down list?

    # if $serverName is "*" then do not target a specific server

    if ($serverName -eq "*")
    {
        $tempObjects   = Get-ADUser -Filter * -Properties $propertyList -SearchBase $targetSearchBase
    } else {   
        $tempObjects   = Get-ADUser -Filter * -Properties $propertyList -Server $serverName -SearchBase $targetSearchBase
    }

    Write-Host "Get-TargetObjectList: " $serverName
    $targetObjects = $tempObjects | Select-Object -Property $propertyList | Sort-Object -Property Name
    return $targetObjects
}


推荐答案

在阅读了Mike Garuccio和Andy Simmons的答案之后,我决定剥离除以下内容以外的所有内容,然后看一台服务器,这是我最近的服务器。
我遇到了可重复的事件组合。

After reading Mike Garuccio and Andy Simmons answers I decided to strip away everything except the below and look at a single server, which is my closest server. I encountered a strange combination of events which is reproducible.

$stopwatch = New-Object System.Diagnostics.Stopwatch
$stopwatch.Start()

$targetSearchBase = "OU=User Accounts,DC=XXX,DC=XXX,DC=com"
$propertyList  = "Enabled", "DistinguishedName", "Name", "department", "givenName","displayName","CanonicalName", "Description"
#$propertyList  = "Enabled", "DistinguishedName", "Name", "department", "givenName","sn","displayName","CanonicalName", "Description"
$serverName = "TARGET_SERVER_NAME"

$tempObjects = Get-ADUser -Filter * -Properties $propertyList -Server $serverName -SearchBase $targetSearchBase

#server not specified
#$tempObjects = Get-ADUser -Filter * -Properties $propertyList -SearchBase $targetSearchBase
$targetObjects = $tempObjects | Select-Object -Property $propertyList | Sort-Object -Property Name

$stopwatch.Stop()
$elapsedTime = $stopwatch.Elapsed
$elapsed = "Elapsed time HH:MM:SS = $($elapsedTime)"
Write-Host "Server: " $serverName
Write-Host "server data retrieved: " $elapsed

如果我未指定服务器,则列表将在不到1秒的时间内获取

If I do not specify a server, the list is retrieved in less than 1 second

 $tempObjects = Get-ADUser -Filter * -Properties $propertyList -SearchBase $targetSearchBase

指定我最近的服务器,列表将在18秒内检索

If I do specify my closest server, the list is retrieved in 18 seconds

 $tempObjects = Get-ADUser -Filter * -Properties $propertyList -Server $serverName -SearchBase $targetSearchBase

浏览所有对象属性后,我注意到该命令已检索到

After looking through all of the object properties I noticed that the command retrieved the property "Surname" and "sn", even though I had only chosen "sn".

 $tempObjects | Get-Member 

这是因为默认情况下,Get-ADUser提取其他属性,其中 Surname是一个其中的一个(请参见下面的链接)。一旦删除了对 sn属性的请求,即使指定了服务器,数据也将在3秒钟内获得。然后,我测试了距离最远的服务器,该服务器从检索到的属性中删除 sn后仅花费了6秒钟,而与此相比则仅花费了42秒钟。

This is because Get-ADUser pulls other properties by default, where "Surname" is one of them (see the link below). Once I removed my request for the "sn" property, even with specifying the server, the data was obtained in 3 seconds. I then tested the server that is furthest away and that took only 6 seconds after removing "sn" from the retrieved properties, verses 42 seconds with it.

 Select-Object -Property $propertyList

我发现了另外一个奇怪之处。如果包含Select-Object语句,则在属性列表中包含 sn时,解析时间将急剧地增加,但

There is one more oddity that I found. When the Select-Object statement is included, the resolution time goes up dramatically but only when "sn" is included in the property list.

我现在知道如何更精确地解决问题并可以解决它,但是目前我还没有关于异常原因的具体答案。希望这个问题会对其他人有所帮助。

I now know how to more precisely target the problem and can resolve it but at this time I don't have a concrete answer as to why the anomaly exists. Hopefully, this question will help someone else.

http://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser -default-and-extended-properties.aspx

这篇关于定位特定服务器时,如何使Get-ADUser更好地执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆