在powershell中使用get-aduser指定域控制器

时间:2014-12-08 16:25:27

标签: powershell active-directory

Get-ADUser -identity $ntaccount1 -properties name, samaccountname, mail, enabled, passwordlastset

在powershell中查找用户帐户信息时,是否可以指定要使用的域控制器?我们有一些DC可以比其他DC更快地获得数据。

3 个答案:

答案 0 :(得分:14)

来自Get-Help Get-ADUser -Parameter *

-Server <string>
    Specifies the Active Directory Domain Services instance to connect to, by providing one of the following values for a 
    corresponding domain name or directory server. The service may be any of the following:  Active Directory Lightweight Domain 
    Services, Active Directory Domain Services or Active Directory Snapshot instance.
    Domain name values:
      Fully qualified domain name
        Examples: corp.contoso.com
      NetBIOS name
        Example: CORP

    Directory server values:
      Fully qualified directory server name
        Example: corp-DC12.corp.contoso.com
      NetBIOS name
        Example: corp-DC12
      Fully qualified directory server name and port
        Example: corp-DC12.corp.contoso.com:3268

    The default value for the Server parameter is determined by one of the following methods in the order that they are listed:
      -By using Server value from objects passed through the pipeline.
      -By using the server information associated with the Active Directory PowerShell provider drive, when running under that drive.
      -By using the domain of the computer running Powershell. 

    The following example shows how to specify a full qualified domain name as the parameter value.
      -Server "corp.contoso.com"

    Required?                    false
    Position?                    named
    Default value                
    Accept pipeline input?       false
    Accept wildcard characters?  false

答案 1 :(得分:10)

我知道这是一个古老的问题,但我想扩大给出的答案,以帮助其他有类似疑问的人。

以下允许您定义特定的域控制器,整个脚本都可以使用...当Get-ADUser,New-ADUser可用-server参数时,为什么要这样做? ,Set-ADObject等?

我把一个创建AD用户的脚本放在一起,设置多个属性并创建一个交换邮箱 - 但是,一组属性围绕2008 R2用户帐户上的RDS属性,这些属性不能在New- ADUser便有。我必须创建一个调用ADSI的函数,并使用psbase.invokeSet来更新设置。我不知道-server的参数设置。

这本身并不是什么大问题,但该脚本还为用户创建了一个Exchange邮箱。由于我的Exchange服务器与我的工作站位于不同的AD站点中,因此在我的本地DC上创建了用户帐户,但未设置邮箱,因为与Exchange服务器位于同一站点的DC尚未收到复制副本新用户帐户。

我找到的解决方案如下,并且是http://www.joseph-streeter.com/?p=799

的礼貌

加载导入模块activedirectory 后,您将可以访问 New-PSDrive 命令行开关中的AD选项,其中包括其他所有内容,您可以定义新的Active Directory与之合作的提供商。

New-PSDrive -Name <<NameofYourChoice>> -PSProvider ActiveDirectory -Server <<DC Server>> -Root "//RootDSE/" -Scope Global

创建后,您可以使用以下命令更改工作提供程序。

CD <<NameofYourChoice>>:

要查看现有的提供商列表,请键入 Get-PSDrive 。 AD是使用ActiveDirectory命令行开关时创建的默认Active Directory提供程序。您还应该看到新创建的提供商。

因此,例如,如果我的远程DC被称为RemoteDC,我将运行:

New-PSDrive -Name RemoteAD -PSProvider ActiveDirectory -Server RemoteDC -Root "//RootDSE/" -Scope Global

创建一个名为RemoteAD的新Provider。如果我然后运行:

CD RemoteAD:

脚本或活动shell中的所有其他与活动目录相关的命令都将与新的Provider RemoteAD一起使用。如果我需要更改回原始提供商,我只需输入

即可
CD AD:

希望有人觉得这很有用......

答案 2 :(得分:0)

这就是我用的:

Get-ADUser -server dcservername.domain.local -identity username
相关问题