Simple snippet on how to Block/activate users programmatically in drupal 8.
<?php
/**
* @param $variables
*/
function mymodule_preprocess_page(&$variables)
{
$result = \Drupal::entityQuery("user")
->execute();
$storage_handler = \Drupal::entityTypeManager()->getStorage("user");
foreach ($result AS $user) {
$entity = $storage_handler->load($user);
// activate users
$entity->activate();
// block users
// $entity->block();
$storage_handler->save($entity);
}
}