Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #Test
  2. #Powershell script to create custom SCCM collection in root with a list of computers in a text file.
  3.  
  4. $collectiondir = "D:\Collections\"
  5. md $collectopmdir
  6. $collectionname = "SCCM_Removal_Collection"
  7. #Add new collection based on the file name
  8. try {
  9. New-CMDeviceCollection -Name $collectionname -LimitingCollectionName "All Systems"
  10. }
  11. catch {
  12. "Error creating collection - collection may already exist: $collectionname" | Out-File "$collectiondir\$collectionname`_invalid.log" -Append
  13. }
  14.  
  15. #Read list of computers from the text file
  16. $computers = Get-Content "C:\users\User\desktop\SCCM_Removal.txt"
  17. foreach($computer in $computers) {
  18. try {
  19. Add-CMDeviceCollectionDirectMembershipRule -CollectionName $collectionname -ResourceId $(get-cmdevice -Name $computer).ResourceID
  20. }
  21. catch {
  22. "Invalid client or direct membership rule may already exist: $computer" | Out-File "$collectiondir\$collectionname`_invalid.log" -Append
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement