如何使用PowerShell脚本向位于另一台服务器上的LDAP Active Directory添加/更新用户数据?

如何使用PowerShell脚本向位于另一台服务器上的LDAP Active Directory添加/更新用户数据?,powershell,active-directory,ldap,Powershell,Active Directory,Ldap,我想添加/更新位于另一台服务器上的Active Directory数据。我有服务器的详细信息,但我不知道怎么做。但是,如果从同一台服务器运行PowerShell脚本,我知道如何添加/更新数据 如果我通过位于同一服务器上的PowerShell脚本添加/更新数据,下面是我的代码。有谁能建议我如何向位于另一台服务器上的Active Directory添加/更新数据 代码 在创建/验证用户之前,需要包含用于连接到另一台服务器的-Server参数 另外,我认为您的意思是将-Filter作为Get-ADUs

我想添加/更新位于另一台服务器上的Active Directory数据。我有服务器的详细信息,但我不知道怎么做。但是,如果从同一台服务器运行PowerShell脚本,我知道如何添加/更新数据

如果我通过位于同一服务器上的PowerShell脚本添加/更新数据,下面是我的代码。有谁能建议我如何向位于另一台服务器上的Active Directory添加/更新数据

代码


在创建/验证用户之前,需要包含用于连接到另一台服务器的
-Server
参数

另外,我认为您的意思是将
-Filter
作为
Get-ADUser cmdlet
的参数,而不是-F

-服务器

指定要连接到的Active Directory域服务实例,方法是为 相应的域名或目录服务器。服务可以是任何形式 以下各项之一:Active Directory轻型域服务,Active Directory 目录域服务或Active Directory快照实例


非常感谢。你能提供我完整的行如何写服务器的详细信息。实际上服务器有URL、用户名和密码。序列应该是什么?我需要把它分开吗?以下是
服务器详细信息的示例:URL:10.556.886.55,用户名:derdlgdeo,密码:maron97
你能在回答中提供我的详细信息吗?@NanjiMange-据我所知,任何服务器都不能拥有IP=
10.556.886.55
;请核对一下。此外,您不应向任何人透露任何凭据。请删除您以前的评论!关于确切的命令,请参考此链接:.@NanjiMange-如该链接中所述,您应该执行:
$secpasswd=ConvertTo SecureString“maron97”-AsPlainText-Force
$mycreds=New Object System.Management.Automation.PSCredential(“derdlgdeo”、$secpasswd)
获取ADUser-Filter{SamAccountName-eq$Username}-服务器10.556.886.55-凭证$mycreds
谢谢。我试过了。我有个问题。以前,我正在从我的一台服务器执行PowerShell脚本。现在,我正在尝试从本地系统(windows 10-没有Active Directory)执行脚本,我收到以下错误
导入模块:未加载指定的模块“Active Directory”,因为在任何模块目录中都找不到有效的模块文件。
请,这和我必须从服务器执行PowerShell脚本类似吗?我知道这是一个愚蠢的问题,但我是PowerShell脚本的新手。
# Import active directory module for running AD cmdlets
Import-Module activedirectory

#Store the data from ADUsers.csv in the $ADUsers variable
$ADUsers = Import-csv C:\it\powershell_create_bulk_users\bulk_users1_quote.csv

foreach ($User in $ADUsers)
{
    $Username   = $User.username
    $Password   = $User.password
    $Firstname  = $User.firstname
    $Lastname   = $User.lastname
    $OU         = $User.ou #This field refers to the OU the user account is to be created in
    $Password = $User.Password

    if (Get-ADUser -F {SamAccountName -eq $Username})
    {
         Write-Warning "A user account with username $Username already exist in Active Directory."
    }
    else
    {
        New-ADUser `
            -SamAccountName $Username `
            -UserPrincipalName "$Username" `
            -Name "$Firstname $Lastname" `
            -Path $OU `
            -AccountPassword (convertto-securestring $Password -AsPlainText -Force) -ChangePasswordAtLogon $True           
    }
}
Get-ADUser -Filter {SamAccountName -eq $Username} -Server a.b.c.d ...
# reference from https://docs.microsoft.com/en-us/powershell/module/addsadministration/get-aduser?view=win10-ps

New-ADUser ... -Server a.b.c.d ... 
# reference from https://technet.microsoft.com/fr-fr/library/hh852238(v=wps.630).aspx