User Removal

I’m trying to remove all but one user (admin) and all but the standard (full,read,right) groups so I can put in a new set of groups/user, I’m no fairly new to scripting but have gotten part way there. No of the other standard methods work. So far I have tried variation of this:

:foreach i in=[/user find] do={:if ([:typeof [:find [/user get $i name] [:and $i “!=admin”]]]) do={/user remove $i}}


Which of course does not work. I can delete all but admin no problem but then it errors out as of course you can not delete the last user with full rights.

I would do something like this. If the name does not equal “admin”, then remove the user.
:foreach i in=[/user find] do={
:if ([/user get $i name] != “admin”) do={
/user remove $i
}
}And something similar for the groups:
:foreach i in=[/user group find] do={
:local name [/user group get $i name]
:if ($name != “full” && $name != “read” && $name != “write”) do={
/user group remove $i
}
}

Thanks that works great, …I was at least pretty close! :smiley:

Didn’t find accept a condition? e.g.
/user remove [/user find where name!=“admin”]/user group remove [/user group find where name!=“full” && name!=“read” && name!=“write”]

I like your code boen, more succinct! Thanks :sunglasses: