将 Get-ADReplicationStie 导入到数组中



我看过,我一直在用头撞墙。我敢肯定,这可能是我错过的简单东西。我正在尝试将 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

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

最新更新