How can I programmatically copy all blocks of a given theme into the same regions of a new theme? I would like to switch admin themes from a core theme (seven) to a custom sub-theme so I can add some customization without hacking core.

When I install the new sub-theme it creates all the block placement settings and leaves them header or content. I haven't changed any regions between the two themes, and just want to copy all the blocks from the seven theme to the current theme. I know I can check block settings with block plugin manager (plugin.manager.block) but I don't know what blocks to edit. I would like to know how to get a list of all the blocks from the old theme and copy all the placement to new theme programmatically.
You can entity query your relevant block config then create a cloned entity object via Block::createDuplicateBlock() then modify the sub-theme clones before saving the new block config into sub-theme region.

For example: 

$block_ids = \Drupal::entityQuery('block')-&gt;condition('theme', 'my_base_theme')-&gt;condition('region','my_region')-&gt;execute();
foreach ($block_ids as $block_id) {
  $parent_block = \Drupal\block\Entity\Block::load($block_id);

  $new_id = str_replace('my_base_theme', 'my_sub_theme', $parent_block-&gt;get('id'));
  $child_block = $parent_block-&gt;createDuplicateBlock($new_id, 'my_sub_theme');
  // @TODO: set other properties that might need to be unique to this new theme's block

  $child_block-&gt;save();
}