本文介绍了如何使用PowerShell脚本向位于另一台服务器上的LDAP Active Directory添加/更新用户数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to add/update data of Active Directory located on another server. I have server details but I don't know how to do it. However, I know how to add/update data if I run PowerShell Script from same server.

这是我的代码,如果我通过位于同一服务器上的PowerShell脚本添加/更新数据,这些代码将起作用.有人可以建议我如何向另一台服务器上的Active Directory添加/更新数据吗?

Here is my code which work if I add/update data by PowerShell Script located to same server. Can anybody please suggest me how can I add/update data to Active Directory located on another server?

代码

# 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           
    }
}

推荐答案

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

You need to include the -Server <string> parameter for connecting to another server before creating / validating the user.

此外,我认为您将-Filter用作Get-ADUser cmdlet的参数,而不是-F.

Also, I think you meant -Filter as the parameter with Get-ADUser cmdlet, and not -F.

通过提供以下值之一来指定要连接的Active Directory域服务实例: 相应的域名或目录服务器.该服务可以是任何 以下各项:Active Directory轻型域服务,活动 目录域服务或Active Directory快照实例. ...

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. ...

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

这篇关于如何使用PowerShell脚本向位于另一台服务器上的LDAP Active Directory添加/更新用户数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 01:04