code: public function actionImportAllUsers()
      {
          \Yii::warning("-- Starting import from Active Directory --");
          $results = \Yii::$app->ad->getDefaultProvider()->
                  search()->
                  select("samaccountname")->
                  where('objectClass','=','user')->
                  where('objectCategory','=','person')->
                  paginate(999);
          
          $userNamesToAdd = [];
          foreach($results->getResults() as $ldapUser) {
              $accountName = $ldapUser->getAttribute("samaccountname",0);
              if ($accountName != null) {
                  array_push($userNamesToAdd, $accountName);
              }
          }
  
          
          $c=0;
          \Yii::warning("-- Found " . count ($userNamesToAdd) . " users --");
          foreach ($userNamesToAdd as $userName) {
              $c++;
              
              \Yii::warning("-- Working on user " . $userName . " --");
              $userObject = \Edvlerblog\Adldap2\model\UserDbLdap::createOrRefreshUser($userName);
              
              if ($userObject != null) {
                  \Yii::warning("User " . $userName . " created");
              } else {
                  \Yii::warning("User " . $userName . " NOT created");
              }
              
          }
          \Yii::warning("-- End import from Active Directory --");
          
       }
docs: Import all users from LDAP, assign roles and account status. Run this command with cron or another scheduler every X minuten/hours/days.