首页 > 解决方案 > 创建多个广告组并设置电子邮件的脚本(不使用交换)

问题描述

Powershell新手在这里。我需要一个脚本来创建批量广告组并设置该组的电子邮件地址。我们不使用交换。不使用交换时,我无法找到好的示例。

$Example = get-content c:\temp\Example.txt

foreach($Example in $Example){

New-ADGroup -Name "$Example.###" -SamAccountName "$Example.###" -Email "$Example.###@Anywhere.com" -ParentContainer "OU=THERE,OU=Organization,DC=HERE,DC=NET" -GroupType "Security" -GroupScope "Global"

}

标签: powershell

解决方案


New-AdGroup没有参数Email。你将不得不使用

-OtherAttributes @{mail = "$Example.###@Anywhere.com"}

PS。如果变量后面的点导致问题,你也可以像这样格式化

-OtherAttributes @{mail = ('{0}.###@Anywhere.com' -f $Example)}

推荐阅读