In the book version, the Dead Men of DunharrowDead Men of Dunharrow were cursed by Isildur after they broke their oath to aid him in the War of the Last Alliance. By later assisting Aragorn, Ilsidur's heir, the curse was broken. Since their task was to aid, they did not need to do more than drive away the Corsairs of Umbar, allies of Sauron, which allowed Aragorn to gather the living warriors of the region to him and sail with them on the Corsair's ships to the battle at Minis Tirith. Peter Jackson embellished the role of the cursed men of Dunharrow in the film by including them in the Battle of the Pelennor Fields. So
So, the answer to the question is
In order to lift the curse, all they needed to do was to aid Aragorn in his his quest to defeat Sauron, not defeat Sauron himself.