Thanks for the answer, there is just a typo in the awk command: should be $1_$4 instead of $1_$3 (if one wants the bp coordinates in the ID, which I think would usually be the case), and there is a missing $3 as well:
awk '{if($2 == ".") {print $1,$1"_"$4,$3,$4,$5,$6} else {print $0}}' myfile.bim > myfileClean.bim