我想添加/更新位于另一台服务器上的 Active Directory 数据。我有服务器详细信息,但我不知道该怎么做。但是,如果我从同一服务器运行 PowerShell 脚本,我知道如何添加/更新数据。
这是我的代码,如果我通过位于同一服务器的 PowerShell 脚本添加/更新数据,该代码将起作用。有人可以建议我如何向位于另一台服务器上的 Active Directory 添加/更新数据吗?
Code
# 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>
用于在创建/验证用户之前连接到另一台服务器的参数。
另外,我认为你的意思是-Filter
作为参数Get-ADUser cmdlet
,而不是-F。
-Server
通过为 a 提供以下值之一来指定要连接到的 Active Directory 域服务实例
相应的域名或目录服务器。该服务可以是任何
以下各项:Active Directory 轻量级域服务、Active
目录域服务或 Active Directory 快照实例。 ...
Get-ADUser -Filter {SamAccountName -eq $Username} -Server a.b.c.d ...
# reference from https://learn.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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)