【发布时间】:2015-02-06 08:45:52
【问题描述】:
Get-ADUser -identity $ntaccount1 -properties name, samaccountname, mail, enabled, passwordlastset
在 powershell 中查找用户帐户信息时,是否可以指定要使用的域控制器?我们有一些 DC 可以比其他 DC 更快地获取数据。
【问题讨论】:
标签: powershell active-directory
Get-ADUser -identity $ntaccount1 -properties name, samaccountname, mail, enabled, passwordlastset
在 powershell 中查找用户帐户信息时,是否可以指定要使用的域控制器?我们有一些 DC 可以比其他 DC 更快地获取数据。
【问题讨论】:
标签: powershell active-directory
From 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
【讨论】:
我知道这是一个老问题,但我想扩展给出的答案,以帮助其他有类似疑问的人。
以下允许您定义一个特定的域控制器,整个脚本都可以使用它...当 -server 参数可用于 Get-ADUser、New-ADUser 时,为什么要这样做, Set-ADObject 等?
好吧,我整理了一个脚本,该脚本创建了一个 AD 用户、设置多个属性并创建了一个交换邮箱 - 但是,一组属性围绕 2008 R2 用户帐户上的 RDS 属性,不能从 New-广告用户。我必须创建一个调用 ADSI 并使用 psbase.invokeSet 更新设置的函数。我知道 -server 没有参数设置。
这本身没什么大不了的,但脚本也会为用户创建一个 Exchange 邮箱。由于我的 Exchange 服务器与我的工作站位于不同的 AD 站点,因此在我的本地 DC 上创建了用户帐户,但未设置邮箱,因为与 Exchange 服务器位于同一站点的 DC 尚未收到复制副本新用户帐户。
我找到的解决方案如下,由http://www.joseph-streeter.com/?p=799提供
加载 import-module 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 提供程序。您还应该看到新创建的 Provider。
例如,如果我的远程 DC 被称为 RemoteDC,我会运行:
New-PSDrive -Name RemoteAD -PSProvider ActiveDirectory -Server RemoteDC -Root "//RootDSE/" -Scope Global
创建一个名为 RemoteAD 的新 Provider。如果我然后运行:
CD RemoteAD:
脚本或活动 shell 中所有与活动目录相关的命令都将与新的提供程序 RemoteAD 一起使用。如果我需要改回原来的 Provider,我只需输入
CD AD:
希望有人觉得这很有用...
【讨论】:
这是我用的:
Get-ADUser -server dcservername.domain.local -identity username
【讨论】: