Create query from list RRS feed

  • Question

  • Hello, 

    I am trying to create a sccm collection query from simple text list. 

    This is powershell command i have created: 

    $computerlist= Get-Content C:\Install\collection_from_list\list.txt
    $Qeury= "select * from SMS_R_System where SMS_R_System.NetbiosName in (""" + ($computerlist -Join ",") + """)"

    I need the query to show: 

    select * from SMS_R_System where SMS_R_System.NetbiosName in ("NTAS102084B0Z","NTAS102084B03")

    Instead i get: 

    select * from SMS_R_System where SMS_R_System.NetbiosName in ("NTAS102084B0Z,NTAS102084B03")

    Can someone help? 

    Thank you very much


    • Edited by Amir Atary Monday, September 2, 2019 11:48 AM
    Monday, September 2, 2019 9:28 AM

All replies

  • To quote members of an array to use in SQL:

    "'{0}'" -f (('one','two','three') -join "','")

    "'{0}'" -f ($list -join "','")


    Monday, September 2, 2019 10:49 AM
  • Thank you

    But i do not know what to do with. 

    Can you insert it into the powershell command?

    Thanks again. 


    Tuesday, September 3, 2019 9:41 AM
  • Hello Amir,

    Hope you are fine. Just checking if your question has solved.

    Please feel free reply in this post so we can keep forums updated.

    Thank you

    Hamid Sadeghpour Saleh Microsoft MCT Regional Lead


    Mark it as answer if your question has solved in order to keep forums updated.

    Saturday, September 7, 2019 10:14 AM
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,


    Just do it.

    Friday, October 4, 2019 8:54 AM
  • Hello Amir, as suggested by jrv you can use that expression as below in your command:

    $Query="select * from SMS_R_System where SMS_R_System.NetbiosName in ("+"`"{0}`"" -f ($computerlist -join "`",`"")+ ")"

    Friday, October 4, 2019 10:54 AM