This observation has been attributed to two individuals and given two names.
The most commonly credited is the behavioral psychologist Abraham Maslow. He had many seminal observations and theories, many of which are still respected and applied. His most famous was the "Hierarchy of Needs," which posited that until basic needs of food and shelter were filled, higher needs would not be pursued.

Anyway, when attributed to him, it's usually called, "Maslow's Maxim." The most precise quote would seem to be,
"If you only have a hammer then you treat everything like a nail."
But as in many oft-repeated saws, it is seen in many forms.

"Baruch's Observation" is the second "person" to whom this quote is attributed. I have seen the name given as "Bruce Lee Baruch," and as "Arthur Conan Doyle Baruch." However, this name may stem from Jeremiah Chapter 51 in the old testament, where Baruch is a messenger of God that helped relay God's message that he was destroying Babylon, which had been referred to previously as "God's Hammer."

For what it's worth, the converse:
Using anything BUT a hammer to hammer a nail into the wall, such as shoes, lamp bases, doorstops, etc.