Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Test
- #Powershell script to create custom SCCM collection in root with a list of computers in a text file.
- $collectiondir = "D:\Collections\"
- md $collectopmdir
- $collectionname = "SCCM_Removal_Collection"
- #Add new collection based on the file name
- try {
- New-CMDeviceCollection -Name $collectionname -LimitingCollectionName "All Systems"
- }
- catch {
- "Error creating collection - collection may already exist: $collectionname" | Out-File "$collectiondir\$collectionname`_invalid.log" -Append
- }
- #Read list of computers from the text file
- $computers = Get-Content "C:\users\User\desktop\SCCM_Removal.txt"
- foreach($computer in $computers) {
- try {
- Add-CMDeviceCollectionDirectMembershipRule -CollectionName $collectionname -ResourceId $(get-cmdevice -Name $computer).ResourceID
- }
- catch {
- "Invalid client or direct membership rule may already exist: $computer" | Out-File "$collectiondir\$collectionname`_invalid.log" -Append
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement