User Manager
User Manager: Remove Used / Expired Users — 7
USER MANAGER script. Finds every User Manager user whose profile is in the 'used' state and deletes the user together with its sessions, profile link and hotspot cookies. Useful for cleaning finished vouchers; run from the Scheduler.
RouterOS 7
# EN: Removes every User Manager user whose profile state is "used" (finished vouchers)
# AR: يحذف كل مستخدم في User Manager حالة بروفايله "used" (الكروت المنتهية)
:foreach up in=[/user-manager/user-profile/find where state=used] do={
# EN: User name and its record | AR: اسم المستخدم وسجله
:local uname [/user-manager/user-profile/get $up user];
:local uid [/user-manager/user/find where name=$uname];
# EN: Remove its sessions, profile link and the user itself | AR: حذف جلساته وربط البروفايل ثم المستخدم نفسه
/user-manager/session/remove [find where user=$uname];
/user-manager/user-profile/remove $up;
/user-manager/user/remove $uid;
# EN: Remove its hotspot cookies so it cannot auto-login | AR: حذف كوكيز الهوتسبوت حتى لا يدخل تلقائياً
/ip hotspot cookie remove [find where user=$uname];
:log warning ("User Manager: removed used user " . $uname);
}