How to programmatically set user state to "active" Is it possible to programmatically set all users to active?

This problem arises because I am trying to display my users using Views, but because my migrated users are "blocked", I cannot expose them to Views.

Could someone provide a snippet of code or a tutorial on how to set user status to active?

This is the code that I need to execute at the beginning.

define('DRUPAL_ROOT', getcwd()); 
$_SERVER['REMOTE_ADDR'] = "localhost"; 
require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; 
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); 

// Set the active DB 
db_set_active('sage');
You can use a combination of user_load_multiple() and user_save() to update the status property of the users:

$uids = db_query('SELECT uid FROM {users}')-&gt;fetchCol();
foreach (user_load_multiple($uids) as $account) {
  $account-&gt;status = 1;
  user_save($account);
}


It's worth bearing in mind that any mail notifications you have set to inform users of their account status will be invoked using this method.

If you don't want that to happen I think you'll have to go directly into the {users} table and set the status manually (not recommended):

db_update('users')
  -&gt;fields(array('status' =&gt; 1))
  -&gt;execute();