Powershell 按文件移动广告组
我是PS新手,正在做我的第一步。Powershell 按文件移动广告组,powershell,active-directory,Powershell,Active Directory,我是PS新手,正在做我的第一步。 我有一个文件名为“C:\temp\used\u groups.csv” 该文件包含由Powershell脚本填充的广告组的电子邮件地址,以检查365中正在使用的分发组。 现在我希望能够将它们移动到不同的OU 该文件包含一些广告组的电子邮件地址,如下所示: "RecipientAddress" "test@test.com" "test1@test.com" "test2@test.com" 是否可以仅通过其电子邮件地址属性移动广告组 如何通过组的电子邮件地址属
我有一个文件名为
“C:\temp\used\u groups.csv”
该文件包含由Powershell脚本填充的广告组的电子邮件地址,以检查365中正在使用的分发组。
现在我希望能够将它们移动到不同的OU 该文件包含一些广告组的电子邮件地址,如下所示:
"RecipientAddress"
"test@test.com"
"test1@test.com"
"test2@test.com"
sAMAccountName
属性 $Groups=import-csv "C:\temp\used_groups.csv"
ForEach ($Group in $Groups){
Get-ADGroup -Filter "mail -like $Group "
# rest of script.. not done yet.
}
使用CSV时,必须指定字段名。脚本中的另一个问题是广告过滤器中缺少引号 试试这个:
$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.
}
干杯
Gert Jan使用CSV时,必须指定字段名。脚本中的另一个问题是广告过滤器中缺少引号 试试这个:
$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.
}
干杯
Gert Jan我会这样做:
# 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'"
}
}
我会这样做:
# 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'"
}
}
太棒了!太棒了!