Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Powershell复制Active Directory用户帐户_Powershell_Active Directory - Fatal编程技术网

使用Powershell复制Active Directory用户帐户

使用Powershell复制Active Directory用户帐户,powershell,active-directory,Powershell,Active Directory,我正在构建一个脚本来创建基于CSV的广告用户帐户(到目前为止没有什么特别的;o)。我想添加的一个特殊参数是“从xxx复制”,其中新帐户将是现有帐户的副本(就像广告控制台中的“复制帐户”选项一样) 这可以实现吗?如何实现?这似乎很简单。在CSV中创建一个名为“CopyFromAccount”或其他内容的列 然后,在Import CSV | Foreach循环中抛出if/else语句 If ($_.CopyFromAccount -ne $null) { ... insert code t

我正在构建一个脚本来创建基于CSV的广告用户帐户(到目前为止没有什么特别的;o)。我想添加的一个特殊参数是“从xxx复制”,其中新帐户将是现有帐户的副本(就像广告控制台中的“复制帐户”选项一样)


这可以实现吗?如何实现?

这似乎很简单。在CSV中创建一个名为“CopyFromAccount”或其他内容的列

然后,在
Import CSV | Foreach
循环中抛出if/else语句

If ($_.CopyFromAccount -ne $null) {
     ... insert code to copy AD account here ...
}
Else {
     ... insert code to use other parameters on this line to create the account ...
}
internet上有几个可用于在PowerShell中复制用户的示例。以下是使用Quest AD cmdlet的示例:

要使用Microsoft提供的新ADUser cmdlet而不是Quest,请检查实例参数。有关详细信息,请访问“获取帮助”或以下URL:

它“指定要用作新用户对象模板的用户对象实例。”

并且是这样使用的:

$userInstance = Get-ADUser -Identity "saraDavis"

New-ADUser -SAMAccountName "ellenAdams" -Instance $userInstance -DisplayName "EllenAdams"

我也发现了这一点。我正在寻找一种非任务方法:)(我更喜欢使用标准的工具集,所以我知道它可以在任何地方运行)。我正在寻找“插入要复制的代码”:)我一直在寻找,但没有找到一个实际有效的示例(似乎没有-copyFrom参数或copy-AdUser cmdlet)。我目前正在解决这个问题(只考虑copyFrom帐户中的选定值,而不是复制wole帐户),修改后的答案提供了使用New-ADUser复制用户的示例代码。嗨,又是Chris My bad:我没有足够好地阅读你的第一篇文章(和手册),不知何故,我错过了最后一部分。实例参数正是我需要的。谢谢你的帮助!