Volodymyr Hryma, 29, of Dorchester Avenue, was in an alleyway off North Drive, Hounslow, on March 23 when he was searched by police.
Officers found a folding pocket knife with a three inch blade as well as a small snap bag of cocaine.
Hryma pleaded guilty to possessing a bladed article and Class A drugs at an Uxbridge Magistrates’ Court hearing.
On Monday, April 14, he was given a one-year community order including 300 hours of unpaid work.
He was also ordered to pay £199 costs.