将 Get-ADReplicationStie 导入数组

Import Get-ADReplicationStie into an Array

我看了看,一直在用头撞墙。我确定这可能是我所缺少的简单东西。我正在尝试将 AD 站点列表导入到填充 ComboBox1 的数组中,但我无法让它工作。

我编写这段代码是为了创建一个包含 2 个组合框的表单。第一个组合框需要 基于由 Get-ADReplicationSite 值创建的数组进行填充。在我的实验室中,我有 5 个测试 网站。 如果我有硬编码的网站,它可以正常工作 如果我尝试从 Get-AD 创建数组,我无法让数组正确显示在 组合框 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")

我可以创建表单和组合框。现在我正在努力将 AD 信息放入数组并使用数组填充第一个组合框,它将读取上面的硬编码变量

 ##################################################################################################
    #####   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

不同之处在于它给出了一个字符串列表(非常适合组合框),而不是返回一个对象。