Powershell 将Get-ADReplicationStie导入数组

Powershell 将Get-ADReplicationStie导入数组,powershell,active-directory-group,Powershell,Active Directory Group,我看过了,我的头一直撞在墙上。我肯定我错过了一些简单的东西。我正在尝试将广告站点列表导入到填充ComboBox1的数组中,但无法使其正常工作 我编写这段代码是为了创建一个包含2个组合框的表单。第一个组合框需要 基于Get-AddressApplicationSite值创建的数组填充。在我的实验室里我做了5次测试 地点。 如果我有硬编码的网站,但它的工作 如果我试图从Get广告创建数组,我将无法使数组在中正确显示 组合框1 #####################################

我看过了,我的头一直撞在墙上。我肯定我错过了一些简单的东西。我正在尝试将广告站点列表导入到填充ComboBox1的数组中,但无法使其正常工作

我编写这段代码是为了创建一个包含2个组合框的表单。第一个组合框需要 基于Get-AddressApplicationSite值创建的数组填充。在我的实验室里我做了5次测试 地点。 如果我有硬编码的网站,但它的工作 如果我试图从Get广告创建数组,我将无法使数组在中正确显示 组合框1

####################################################################################################    
#####   This is the section that I use to Create the Arrays
####################################################################################################

## This piece of code works
# If you want to have the sites Hardcoded, use this line
#>
$ADSites=@("S01","S02","S03")

## I can't get this to work
# $ADSites= Get-ADReplicationSite -Filter * | select Description

# Below is a list of Variables that are hard coded. I'm going to convert this to an import of a CSV file
$ADSiteS01=@("AAA","BBB","CCC")
$ADSiteS02=@("DDD","EEE","FFF")
$ADSiteS03=@("GGG","HHH","JJJ")
$ADSiteS04=@("KKK","LLL","MMM")
$ADSiteS05=@("NNN","PPP","QQQ")
我可以创建表单和组合框。现在,我正在努力将广告信息放入数组,并使用数组填充第一个组合框,该组合框将读取上述硬编码变量

 ##################################################################################################
    #####   Now we do stuff
    #### The form keeps asking me to add details so I'm adding details
    ##################################################################################################

    # Populate Combobox 2 When Combobox 1 changes
    $ComboBox1.add_SelectedIndexChanged({
        $combobox2.Items.Clear() # Clear the list
        $combobox2.Text = $null  # Clear the current entry
    # Refresh ComboBox 1 changes    
        Switch ($ComboBox1.Text) {
                "S01"{

                $ADSiteS01 | ForEach { 
                    $combobox2.Items.Add($_)
                }
            }
    # Refresh ComboBox 1 changes    
                "S02"{
                $ADSiteS02 | ForEach {
                    $combobox2.Items.Add($_)
                 }
            }
    # Refresh ComboBox 1 changes    
            "S03"{
                $ADSiteS03 | ForEach {
                    $combobox2.Items.Add($_)
                  }
            }

        }
        $labelClub.Text = $combobox1.Text + "-" + $combobox2.Text + "-" + $textBoxFPS.Text
    })

    $ComboBox2.add_SelectedIndexChanged({
        $labelClub.Text = $combobox1.Text + "-" + $combobox2.Text + "-" + $textBoxFPS.Text
    })

    $textBoxFPS.add_TextChanged({
        $labelClub.Text = $combobox1.Text + "-" + $combobox2.Text + "-" + $textBoxFPS.Text
    })

这是我创建组合框的地方。我会把整个脚本放进去,但是,该网站不让我这样做,并不断要求更多的解释,即使从您的描述中完整地记录了脚本,这可能会解决您的问题:

$ADSites = (Get-ADReplicationSite -filter *).Description
不同之处在于,这会给出一个字符串列表(非常适合组合框),而不是返回一个对象。

>一个hiccup########创建组合框$Combobox1=新对象系统.Windows.Forms.combobox$Combox1.Location='26,25'$Combox1.Size='105,20'$Combox1.items.AddRange($ADSites)#这导致了一个错误>这是一个错误,显示调用带有“1”参数的“AddRange”时出现异常:“值不能为null。参数名称:item”位于Thought3.ps1:50 char:1+$Combobox1.items.AddRange($ADSites)+CategoryInfo:NotSpecified:(:)[],MethodInvocationException+FullyQualifiedErrorId:ArgumentNullException