如何使用 PowerShell 脚本将用户数据添加/更新到位于另一台服务器上的 LDAP Active Directory? [英] How to add/update user data to LDAP Active Directory located on another server using PowerShell script?
问题描述
我想添加/更新位于另一台服务器上的 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:itpowershell_create_bulk_usersulk_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
参数以连接到另一台服务器.
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目录域服务或 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!