I've looked and I've been banging my head against the wall. I'm sure it's probably something simple that I'm missing. I am trying to import a list of AD Sites into the Array that populates ComboBox1 but I can't get it to work.
I've written this code to create a form that has 2 Combo Boxes. The First combo box needs to be populated based on the Array created by the Get-ADReplicationSite value. In my Lab I have 5 test sites. If I have the sites Hardcoded, it works fins however if I try to create the array from the Get-AD, I am not able to get the array to show up properly in ComboBox 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")
I can create the form and the combo boxes. Right now I am struggling with getting the AD information into an Array and using the Array to populate the First Combo Box which will read the above hard coded variables
##################################################################################################
##### 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
})
This is where I create the Combo Boxes. I would put the whole script in however, the site won't let me and keeps asking for more explanation, even though the script is thoroughly documented
From your description, this could fix your problem:
$ADSites = (Get-ADReplicationSite -filter *).Description
The difference is that this gives a list of strings (perfect for a combobox), as opposed to returning an object.