How to set user status drupal 8 I have tried the following code but nothing seems to be working. I have removed the other field just to make focus on status field.

$user = \Drupal\user\Entity\User::create();
$user-&gt;set("status", 0);
$user-&gt;activate();
// Save user
$saved = $user-&gt;save();


Another code is 

$user = \Drupal\user\Entity\User::create();
$user-&gt;status= 0;
$user-&gt;activate();
// Save user
$saved = $user-&gt;save();


But none of the above code is working. Please guide how to set the user status.
Here is my full code

$lang = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();
    $user = \Drupal\user\Entity\User::create();

    $user_data = db_query("SELECT * from eberhard_users ORDER BY uid ASC limit 0,1");

    foreach ($user_data as $delta =&gt; $details) {
        // The Basics
        $password = user_password(8);
        $user-&gt;uid = $details-&gt;uid;
        $user-&gt;created = $details-&gt;created;
        $user-&gt;changed = $details-&gt;login;
        $user-&gt;access = $details-&gt;access;

        $user-&gt;setUsername($details-&gt;name);
        $user-&gt;setPassword($password);
        $user-&gt;setEmail($details-&gt;mail);
        $user-&gt;enforceIsNew();  // Set this to FALSE if you want to edit (resave) an existing user object

        // Optional settings  &lt;-- Thanks to http://drupal8.ovh/ for these suggestions!
        $user-&gt;set("init", $details-&gt;mail);
        $user-&gt;set("langcode", $lang);
        $user-&gt;set("preferred_langcode", $lang);
        $user-&gt;set("preferred_admin_langcode", $lang);
        $user-&gt;set("timezone", 'Pacific/Wallis');
        $user-&gt;set("status", FALSE);
        $user-&gt;activate();
        // Save user
        $saved = $user-&gt;save();die;
    }
There are a number of issues with your code. First, you are setting status as false, then activating. You don't need to set the status as false first. Just create the user, and set activate() on it.

Next, you are trying to set properties directly, like the created. You cannot do that in Drupal 8. You need to use the methods on the user object. So you would use set(). Other properties have methods for setting the property, such as setEmail(). You can view all the methods on the User object here: https://api.drupal.org/api/drupal/core%21modules%21user%21src%21Entity%21User.php/class/User/8.3.x

One other issue is that you are setting the UID. I don't believe you can do this, as the user ID is determined by the auto-increment value in the database, and trying to manually set it, if you can get it to work, will only cause you issues.