【发布时间】:2018-05-04 21:31:39
【问题描述】:
我是 PowerShell 的新手,希望有人能帮助我了解我想要创建的脚本哪里出了问题。
脚本的目的是将名字和姓氏作为强制值,然后存储在 $FirstNames 和 $LastNames 中。然后将它们加在一起并创建 $Samaccountname。 然后将其馈送到 ForEach-Object 循环,为每个提供给 $Samaccountname 的对象创建一个用户帐户,并使用一个为 -otherattributes 提供额外属性的数组。
请看下面我的代码:
Param
(
[Parameter(Mandatory=$True)]
[string[]]$FirstNames
,
[Parameter(Mandatory=$True)]
[string[]]$LastNames
)
#This will create new users with pre-set attributes based on an array.
Import-Module ActiveDirectory
$Samaccountnames = $FirstNames+$LastNames
$OtherAttributes = @{
City="Sunderland"
Department="IT"
Title='1st Line Analyst'
#This is the 'Office' attribute
office='Sunderland IT Building'
Path='OU=Sunderland,OU=North East,OU=Lab Users,DC=*******,DC=***'
}
foreach($Samaccountname in $Samaccountnames)
{
New-ADUser -name $Samaccountname @OtherAttributes
}
这创建了 Samaccount 名称来自 $firstnames 的用户。它也没有应用姓氏属性。
非常感谢
【问题讨论】:
-
您可能希望提供输入脚本的数据示例;特别是名称的格式
标签: powershell