Provide three buttons, whose use would be determined by the default selection you provide the user.
If all are checked initially, and the user only wants to operate on a few, he could uncheck the ones he wants and then user the invert selection.
If none are checked initially, and the user wanted to operate on a few, he could check those and then use the invert selection.
Various combinations of these buttons could be used depending the initial default selection to make the overall process simpler.