It is a form of external rotation and works on the rotator cuff. Related exercises covers the topic in more detail, but I'll emphasize using light weights as the muscles involved are comparatively small.
Using a horizontal cable to put all of the load against the direction of motion, or lying down so that gravity accomplishes the same thing is probably more effective. Nonetheless, I have had a trainer have me perform both variations that you have shown and moving the dumbbell from side to side still works the rotator cuff even if the biceps are maintaining the vertical position of the dumbbell.