[英]move AD group by file
I'm new with PS and doing my first steps.. 我是PS的新手,正在做我的第一步。
I have a file named "C:\\temp\\used_groups.csv"
. 我有一个名为
"C:\\temp\\used_groups.csv"
。
The file has email address of AD Groups populated by Powershell script to check which distributions group are being used in 365. 该文件具有由Powershell脚本填充的AD组的电子邮件地址,以检查365中正在使用哪个通讯组。
Now I want to be able to move them to different OU. 现在,我希望能够将它们移动到其他OU。
the file has some AD group's email address as follow: 该文件具有一些广告组的电子邮件地址,如下所示:
"RecipientAddress"
"test@test.com"
"test1@test.com"
"test2@test.com"
sAMAccountName
attribute by their email address attribute? sAMAccountName
属性? this is what I tried with no success: 这是我没有成功的尝试:
$Groups=import-csv "C:\temp\used_groups.csv"
ForEach ($Group in $Groups){
Get-ADGroup -Filter "mail -like $Group "
# rest of script.. not done yet.
}
When using a CSV you have to specify the fieldname. 使用CSV时,必须指定字段名称。 Another problem in your script is the absence of quotes in the AD filter.
脚本中的另一个问题是AD过滤器中没有引号。
Try this: 尝试这个:
$Groups=import-csv "C:\temp\used_groups.csv"
ForEach ($Group in $Groups){
(Get-ADGroup -Filter "mail -like '$($Group.RecipientAddress)'").samaccountname
# rest of script.. not done yet.
}
Cheers, 干杯,
Gert Jan 杰特·扬
I would do something like this: 我会做这样的事情:
# put the DistinghuishedName of the destination OU here
$destinationOU = "OU=Test,DC=Fabrikam,DC=COM"
# read the CSV and grab the 'RecipientAddress' fields in an array
$emailAddresses = (Import-Csv "C:\temp\used_groups.csv").RecipientAddress
foreach ($email in $emailAddresses){
$GroupToMove = Get-ADGroup -Filter "mail -like '$email'"
if ($GroupToMove) {
# Move-ADObject takes the 'DistinghuishedName' or the 'objectGUID' as Identity parameter
# but it also works when piping the group object itself to it.
$GroupToMove | Move-ADObject -TargetPath $destinationOU
Write-Host "Moved group '$($GroupToMove.Name)'."
}
else {
Write-Warning "Could not find group with email address '$email'"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.