Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delete multiple users

284 views
Skip to first unread message

chr6...@gmail.com

unread,
Mar 8, 2016, 8:54:22 AM3/8/16
to
Is there a way to delete a list of users from an as400 at once?

lae...@gmail.com

unread,
Mar 8, 2016, 3:14:12 PM3/8/16
to
On Tuesday, March 8, 2016 at 8:54:22 AM UTC-5, chr6...@gmail.com wrote:
> Is there a way to delete a list of users from an as400 at once?

don't think so. you could write a command and CL program.


CMD PROMPT('Delete list of users')

PARM KWD(USRPRF) TYPE(*NAME) LEN(10) MAX(32) +
PROMPT('User profile name')




PGM PARM(&Ul)

dcl &ul *char 512
dcl &ulEntryCx *int 2 stg(*defined) +
defvar(&ul 1)
dcl &ulArray *char 500 stg(*defined) +
defvar(&ul 3)
dcl &bx *int 4
dcl &ix *int 4
dcl &userName *char 10

DOFOR VAR(&IX) FROM(1) TO(&ulENTRYCX) BY(1)
chgvar &bx (&ix * 10 - 9)
chgvar &userName %sst(&ulArray &bx 10)
dltusrprf &userName
enddo

endpgm

Mike Colangelo

unread,
Mar 10, 2016, 10:21:56 PM3/10/16
to
On 3/8/2016 5:54 AM, chr6...@gmail.com wrote:
> Is there a way to delete a list of users from an as400 at once?

I've been known to do something like this.

create function do_cmd (command varchar(10000)) returns int
external name 'QSYS/QC2SYS(sytem)'
no sql
parameter style general with nulls



Then:

select authorization_name,
do_cmd('dltusrprf ' || authorization_name)
from qsys2.user_info
where authorization_name in
('TRUMP','CARSON','CRUZ','RUBIO','BUSH','CLINTON','SANDERS','TRUMP')

[put in Trump twice just to be sure I really got the bastard ;-)]

You could add some of the other parameters of the DLTUSRPRF command if
you wished. The integer result of the scalar function will come back as
a 0 if the command completes successfully, or a 1 if it fails.

Technically, this isn't deleting them all at once - the command is
executed once for each row meeting the selection criteria. However,
it's "all at once" in the sense that *you* execute a single statement.

You could also write a simple stored procedure to do this, and you could
make it operate on some real world criteria, such as a profile that was
created before some earlier date and that has not signed on in a long
time, or never.

create procedure delete_inactive_profiles () language sql
begin
declare profile char(10);
declare sqlstate char(5);
declare go_on char(1);
declare delete_profile_cmd char(100);
declare inactive_profiles cursor for
select authorization_name
from qsys2.user_info
where date(creation_timestamp) <= current_date - 2 years
and coalesce(date(previous_signon), '0001-01-01')
<= current_date - 1 years;
declare continue handler for sqlexception
set go_on = 'Y';
open inactive_profiles;
if sqlstate = '00000' then
fetch inactive_profiles into profile;
while sqlstate = '00000' do
set delete_profile_cmd = 'dltusrprf ' || profile;
call qsys2.qcmdexc (delete_profile_cmd);
fetch inactive_profiles into profile;
end while;
close inactive_profiles;
end if;
end;

You may want to add some other error handling and possibly insert a row
for each deleted profile into a log table, as well as add some of the
other parameters for the DLTUSRPRF command to handle objects owned by
the profile, etc.

JTF

unread,
Apr 29, 2016, 8:28:04 PM4/29/16
to
On Tuesday, March 8, 2016 at 8:54:22 AM UTC-5, chr6...@gmail.com wrote:
> Is there a way to delete a list of users from an as400 at once?

I had created a program which is pretty simple.....

--attempts to grab a specificly named csv file from the IFS

--copies it into a PF (only a single column of user profiles)

--Reads PF via SQL

--Attempts to remove user profile(s)

--Deletes IFS file and clears PF
0 new messages