NEW Powershell to add multiple devices to a collection from txt but devices must be a 'Like' clause and not exact

Tocatech

New Member
1
0
1
thanks so much for the article to show us how to add devices to a collection through powershell, it works great. https://www.prajwaldesai.com/add-multiple-devices-to-sccm-collection-using-powershell/

but i have another scenario that i need help with. so i have a list of 200 user accounts the company's device naming policy is that the machine name will always be first name and first 3 letters of the second name eg: Elvis Presley machine name will be Elvispr-wrk or Elvispr-lap

So i would like to modify the script to say... look at the txt file and add any device name that is like Elvispr%.

below is an extract of the script from the article above.

Get-Content "E:\Sources\Import\List_computers.txt" | foreach { Add-CMDeviceCollectionDirectMembershipRule -CollectionName "Computer List" -ResourceID (Get-CMDevice -Name $_).ResourceID }
 

pgnmst

Member
13
2
3
You can just use the Wildcard (*) within the Get-CMDevice function.
Code:
Get-Content "E:\Sources\Import\List_computers.txt" | foreach {
        Add-CMDeviceCollectionDirectMembershipRule -CollectionName "Computer List" -ResourceID (Get-CMDevice -Name "$_*").ResourceID
}