Hello,
I think the better combination would be:
Get-CMCollectionMember
https://learn.microsoft.com/en-us/powershell/module/configurationmanager/get-cmcollectionmember?view=sccm-ps
Get-Content "C:\Temp\ServerList.txt" | foreach {Get-CMDevice} | Export-Csv -Force -NoTypeInformation "c:\temp\sccmcollectioninfo.csv"
or :
$DeviceName = "your device"
$SiteServer = "site server"
$SiteCode ="site name"
(Get-WmiObject -ComputerName $SiteServer -Namespace root/SMS/site_"$SiteCode" -Query "SELECT SMS_Collection.* FROM SMS_FullCollectionMembership, SMS_Collection where name = '$DeviceName' and SMS_FullCollectionMembership.CollectionID = SMS_Collection.CollectionID")
------------------------------------------------------------------------------------------------------------------------------
--If the reply is helpful, please Upvote and Accept as answer--