SHARE
TWEET

Untitled

a guest Jul 19th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top