WMI에서 홀수 형식의 쿼리를 반환하는 PowerShell
-
21-12-2019 - |
문제
SCCM 서버를 대상으로하는 PowerShell 스크립트를 가지고 있으며 PC가 컬렉션에서 가져 와서 ComboBox에 배치하여 선택할 수 있습니다.그러나 ComboBox에 추가되는 결과는 내가 갖고 싶지 않은 것을 갖고 싶지 않은 추가 서식이 추가되어 누군가가 내가 잘못한 곳을 말해 줄 수 있습니까?
출력은이 @ {name= pcname}처럼 보입니다. 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)
}
. 해결책
select Name
대신 select -expandProperty Name
이름 속성이있는 첫 번째 출력 객체가 두 번째 출력 문자열 값 자체
제휴하지 않습니다 StackOverflow