[英]move AD group by file
我是PS的新手,正在做我的第一步。
我有一個名為"C:\\temp\\used_groups.csv"
。
該文件具有由Powershell腳本填充的AD組的電子郵件地址,以檢查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時,必須指定字段名稱。 腳本中的另一個問題是AD過濾器中沒有引號。
嘗試這個:
$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.
}
干杯,
傑特·揚
我會做這樣的事情:
# 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.