Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在powershell中使用get aduser指定域控制器_Powershell_Active Directory - Fatal编程技术网

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

在powershell中使用get aduser指定域控制器,powershell,active-directory,Powershell,Active Directory,在powershell中查找用户帐户信息时,是否可以指定要使用的域控制器?我们有一些DC比其他DC更快地获取数据。来自get Help get ADUser-参数* Get-ADUser -identity $ntaccount1 -properties name, samaccountname, mail, enabled, passwordlastset -服务器 指定要连接到的Active Directory域服务实例,方法是为 相应的域名或目录服务器。该服务可以是以下任一项:Activ

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

来自get Help get ADUser-参数*

Get-ADUser -identity $ntaccount1 -properties name, samaccountname, mail, enabled, passwordlastset
-服务器
指定要连接到的Active Directory域服务实例,方法是为
相应的域名或目录服务器。该服务可以是以下任一项:Active Directory轻型域
服务、Active Directory域服务或Active Directory快照实例。
域名值:
完全限定域名
示例:corp.contoso.com
主机名
示例:公司
目录服务器值:
完全限定目录服务器名称
示例:corp-DC12.corp.contoso.com
主机名
示例:corp-DC12
完全限定的目录服务器名称和端口
示例:corp-DC12.corp.contoso.com:3268
服务器参数的默认值由以下方法之一按列出顺序确定:
-通过使用通过管道传递的对象的服务器值。
-在Active Directory PowerShell提供程序驱动器下运行时,使用与该驱动器关联的服务器信息。
-通过使用运行Powershell的计算机的域。
下面的示例演示如何将完全限定的域名指定为参数值。
-服务器“corp.contoso.com”
必修的?假的
位置?命名
默认值
接受管道输入?假的
是否接受通配符?假的

我知道这是一个有点老的问题,但我想对给出的答案进行扩展,以帮助其他有类似问题的人

下面允许您定义一个特定的域控制器,整个脚本都可以使用它。。。当-server参数可用于获取ADUser、New ADUser、Set ADObject等时,为什么要这样做

我编写了一个脚本,创建了一个广告用户,设置了多个属性,并创建了一个exchange邮箱——但是,有一组属性围绕着2008 R2用户帐户上的RDS属性,而这些属性不能在新ADUser中设置。我必须创建一个调用ADSI的函数,并使用psbase.invokeSet更新设置。我知道-server没有参数设置

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

我找到的解决方案如下,并由

加载导入模块activedirectory后,您将可以访问新PSDrive命令中的AD选项,该命令允许您定义新的Active Directory提供程序来使用

-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
创建名为RemoteAD的新提供程序。如果我接着跑:

New-PSDrive -Name RemoteAD -PSProvider ActiveDirectory -Server RemoteDC -Root "//RootDSE/" -Scope Global
脚本或active shell中所有其他与active directory相关的命令都将与新的提供程序RemoteAD一起使用。如果我需要更改回我原来的提供者,我只需键入

CD RemoteAD:
希望有人觉得这个有用…

这就是我使用的:

CD AD:

哇,我怎么会错过呢。我们说话的时候我在试。我相信这是可行的。
CD RemoteAD:
CD AD:
Get-ADUser -server dcservername.domain.local -identity username