question

RogerRoger-2394 avatar image
0 Votes"
RogerRoger-2394 asked saldana-msft edited

Create a Collection

Hi All

I have a servers list in a text file in the below format. I have a Collection by name MyCollection, i wan to add the servers to this collection by importing the text file. I am connected to configuration manager primary site server, if i execute the below syntax from windows powershell will it work for me.

server01
server02
server03

Get-Content "C:\temp\servers.txt" | foreach { Add-CMDeviceCollectionDirectMembershipRule -CollectionName "MyCollection" -ResourceID (Get-CMDevice -Name $_).ResourceID }


If i want to create a collection and at the same time i want to import the text file how do i do it from windows powershell.

mem-cm-generalmem-cm-co-management
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YoussefSaad avatar image
2 Votes"
YoussefSaad answered

Hi @RogerRoger-2394,

You can use the New-CMDeviceCollection cmdlet to create a new device collection then you add the above command to import your devices.

Regards,


Youssef Saad | Blog: https://youssef-saad.blogspot.com
Please remember to “Accept answer” or upvote for useful answers, thank you!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RahulJindal-2267 avatar image
0 Votes"
RahulJindal-2267 answered

I have personally never used powershell cmdlets to create collections, but the best way to know whether it works or not is to try it out yourself. On a side note, using configmgr powershell cmdlets are known to have worked so I see no reason why things won't work.

I normally create the syntax in excel and copy that in collection query. However, it is not an automated solution, so if you are looking for one then this may not be relevant to you.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RogerRoger-2394 avatar image
0 Votes"
RogerRoger-2394 answered YoussefSaad commented

using configmgr powershell will the below syntax work i.e by importing the csv file.

server01
server02
server03

Get-Content "C:\temp\servers.txt" | foreach { Add-CMDeviceCollectionDirectMembershipRule -CollectionName "MyCollection" -ResourceID (Get-CMDevice -Name $_).ResourceID }

in a single syntax how do i create a collection and add the above servers by importing txt file.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Did you check what I've posted above?

0 Votes 0 ·