如何使用powershell使广告组成为另一个广告组的成员?

如何使用powershell使广告组成为另一个广告组的成员?,powershell,active-directory,windows-server-2008-r2,Powershell,Active Directory,Windows Server 2008 R2,我正在尝试创建批量脚本来创建组,并使一些组成为另一个组(子组)的成员。我想创建组TestGroup1、TestGroup2(TestGroup1的成员)、TestGroup3(TestGroup1的成员) 下面是我的csv文件,其中包含输入组: 批量导入.csv: GroupName,GroupType,GroupLocation,Member TestGroup1,Global,"OU=arSearch", TestGroup2,Global,"OU=arSearch",TestGroup1

我正在尝试创建批量脚本来创建组,并使一些组成为另一个组(子组)的成员。我想创建组TestGroup1、TestGroup2(TestGroup1的成员)、TestGroup3(TestGroup1的成员)

下面是我的csv文件,其中包含输入组:

批量导入.csv:

GroupName,GroupType,GroupLocation,Member

TestGroup1,Global,"OU=arSearch",
TestGroup2,Global,"OU=arSearch",TestGroup1
TestGroup3,Global,"OU=arSearch",TestGroup1
创建组的脚本如下所示:

Import-Module ActiveDirectory
#Import CSV
$csv = @()
$csv = Import-Csv -Path "C:\bulk_import.csv"

#Get Domain Base
$searchbase = Get-ADDomain | ForEach {  $_.DistinguishedName }



#Loop through all items in the CSV
ForEach ($item In $csv)
{
  #Check if the OU exists
  $check = [ADSI]::Exists("LDAP://$($item.GroupLocation),$($searchbase)")

  If ($check -eq $True)
  {
    Try
    {
      #Check if the Group already exists
      $exists = Get-ADGroup $item.GroupName
      Write-Host "Group $($item.GroupName) alread exists! Group creation skipped!"
    }
    Catch
    {
      #Create the group if it doesn't exist
      $create = New-ADGroup -Name $item.GroupName -GroupScope $item.GroupType -Path ($($item.GroupLocation)+","+$($searchbase))
      Write-Host "Group $($item.GroupName) created!"
      if($item.MemberOf -eq ""){
         Write-Host "Group don't have parent"
         }else{
             Add-ADGroupMember -Identity $item.MemberOf -Member $item.GroupName 
           }
    }
  }
  Else
  {
    Write-Host "Target OU can't be found! Group creation skipped!"
  }
}
bulk\u ad\u group\u creation.ps1

Import-Module ActiveDirectory
#Import CSV
$csv = @()
$csv = Import-Csv -Path "C:\bulk_import.csv"

#Get Domain Base
$searchbase = Get-ADDomain | ForEach {  $_.DistinguishedName }

#Loop through all items in the CSV
ForEach ($item In $csv)
{
  #Check if the OU exists
  $check = [ADSI]::Exists("LDAP://$($item.GroupLocation),$($searchbase)")

  If ($check -eq $True)
  {
    Try
    {
      #Check if the Group already exists
      $exists = Get-ADGroup $item.GroupName
      Write-Host "Group $($item.GroupName) alread exists! Group creation skipped!"
    }
    Catch
    {
      #Create the group if it doesn't exist
      $create = New-ADGroup -Name $item.GroupName -GroupScope $item.GroupType -Path ($($item.GroupLocation)+","+$($searchbase)) -Member $item.Member
      Write-Host "Group $($item.GroupName) created!"
    }
  }
  Else
  {
    Write-Host "Target OU can't be found! Group creation skipped!"
  }
}
但它总是打印出找不到参数-成员,请告知


我正在使用windows server 2008 R2。

我可以通过如下更改脚本来解决此问题:

Import-Module ActiveDirectory
#Import CSV
$csv = @()
$csv = Import-Csv -Path "C:\bulk_import.csv"

#Get Domain Base
$searchbase = Get-ADDomain | ForEach {  $_.DistinguishedName }



#Loop through all items in the CSV
ForEach ($item In $csv)
{
  #Check if the OU exists
  $check = [ADSI]::Exists("LDAP://$($item.GroupLocation),$($searchbase)")

  If ($check -eq $True)
  {
    Try
    {
      #Check if the Group already exists
      $exists = Get-ADGroup $item.GroupName
      Write-Host "Group $($item.GroupName) alread exists! Group creation skipped!"
    }
    Catch
    {
      #Create the group if it doesn't exist
      $create = New-ADGroup -Name $item.GroupName -GroupScope $item.GroupType -Path ($($item.GroupLocation)+","+$($searchbase))
      Write-Host "Group $($item.GroupName) created!"
      if($item.MemberOf -eq ""){
         Write-Host "Group don't have parent"
         }else{
             Add-ADGroupMember -Identity $item.MemberOf -Member $item.GroupName 
           }
    }
  }
  Else
  {
    Write-Host "Target OU can't be found! Group creation skipped!"
  }
}