Here you go!!
Map<Id, Contact> conmap = new Map<Id, Contact>([select id from contact where Account.RecordTypeId='012xxxxxxxxxxxx']);//add filter based on your need List<User> usersToUpdate = new List<User>(); for(User u : [Select Id, IsActive, IsPortalEnabled from User where ContactId in :conmap.keySet()]){ if(u.IsActive || u.IsPortalEnabled ){ u.IsActive = false; u.IsPortalEnabled = false; usersToUpdate.add(u); } } if (usersToUpdate.size()>0){ update usersToUpdate; }