Question

I have a powershell script that targets our SCCM server and it grabs PC's from a collection and places them in a combobox so they can be selected. However the results being added to the combobox have extra formatting added that i do not wish to have, can someone tell me where i've gone wrong?

The output looks like this @{Name=PCNAME} I would like to have just the PCNAME

$Collection = Get-WmiObject -ComputerName $siteServer -NameSpace "ROOT\SMS\site_$SiteCode" -Class SMS_Collection  | where {$_.Name -eq "$CollectionName"}


$computerNames = Get-WmiObject -ComputerName $SiteServer -Namespace  "ROOT\SMS\site_$SiteCode" -Query "SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID='$($Collection.CollectionID)'" | select Name
    foreach ($computer in $computerNames)
    {
        $ComboBox1.Items.Add($computer)
    }
Was it helpful?

Solution

Instead of select Name, use select -expandProperty Name

The first outputs objects with a Name property, the second outputs the string values themselves

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top