将Get-ADReplicationStie导入到数组中

问题描述 投票:0回答:1

我已经看过,而且我的头一直撞在墙上。我敢肯定,这可能是我所缺少的简单事物。我正在尝试将AD网站列表导入到填充ComboBox1的数组中,但无法正常工作。

我已编写此代码来创建具有2个组合框的表单。第一个组合框需要是根据由Get-ADReplicationSite值创建的Array进行填充。在我的实验室中,我有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
    })

这是我创建组合框的地方。我会把整个脚本放进去,尽管该脚本有完整的文档记录,但网站不允许我继续询问更多的解释

powershell active-directory-group
1个回答
0
投票

根据您的描述,这可以解决您的问题:

© www.soinside.com 2019 - 2024. All rights reserved.