Get user by username (or any other attributes) in Moodle
You can do as the following snippet to get the user object by username (or any other attributes)
#!/usr/bin/php
<?php
define('CLI_SCRIPT', true);
require_once('../config.php');
global $DB;
$user = $DB->get_record('user', array('username'=>'myusername'));
print_r($user);
exit;
?>
Reference: https://docs.moodle.org/dev/Data_manipulation_API
#!/usr/bin/php
<?php
define('CLI_SCRIPT', true);
require_once('../config.php');
global $DB;
$user = $DB->get_record('user', array('username'=>'myusername'));
print_r($user);
exit;
?>
Reference: https://docs.moodle.org/dev/Data_manipulation_API