Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 按文件移动广告组_Powershell_Active Directory - Fatal编程技术网

Powershell 按文件移动广告组

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" 是否可以仅通过其电子邮件地址属性移动广告组 如何通过组的电子邮件地址属

我是PS新手,正在做我的第一步。
我有一个文件名为
“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'"
        }
    }
    

    太棒了!太棒了!