This comes amid growing concern for tourists visiting just for drugs and foreign dealers selling illegally at home.
The ban will start in three southern provinces from May and will be nationwide by the end of the year.
Dutch residents will still be able to use the cafes as long as they have valid identification or a “weed pass”.
Café owners argued at The Hague district court that the ban discriminated against foreigners and their lawyer said he would launch an appeal immediately.
However at the end of 2010, EU judges ruled that the authorities are not in breach of European single market laws by banning foreigners from buying marijuana that is on sale to the Dutch.
Michael Veling, a spokesman for the Dutch Cannabis Retailers Association said: “It is going to cost me 90% of my turnover.
“That is a very good reason for anyone to oppose any plan. Second it puts our customers in a very difficult spot, because why do you have to register to buy a substance that is still illegal?”
Small amounts of cannabis have been legally bought and smoked in the Netherlands since 1976.
A third of Amsterdam’s tourists visit to smoke cannabis, so the citys mayor Eberhard van der Laan is aiming to reach a compromise with the national government, which relies on municipalities and local police to enforce drug laws.