The text of the hadith is as follows:
بعثت بين يدي الساعة بالسيف حتى يعبد الله وحده لا شريك له، وجعل رزقي تحت ظل رمحي، وجعل الذلة والصغار على من خالف أمري، ومن تشبه بقوم فهو منهم
I have been sent ahead of the Hour with the sword so that Allah will be worshipped alone, and my provision has been placed in the shade of my spear, and humiliation has been decreed for those who go against my command, and whoever imitates a people is one of them.
— Musnad Ahmad 5115 - translation from islamqa.info
A shortened version (from "my provision" to "my command") has been recorded in Saheeh Bukhari as a chain-less report before hadith 2914 . Another truncated version, consisting of only the last phrase, has been recorded in Sunan Abu Dawud 4031.
The complete hadith is recorded in Musnad Ahmad 5114, 5115, 5667, Musannaf Ibn Abi Shaybah 19401, 19437, 33010 , Sharh Mushkil al-Athaar 231, Shu'ab al-Eemaan 1154 etc.
As noted by scholars there is disagreement on the status of one of the transmitters of the hadith named Abdur Rahman bin Thabit bin Thawban (عبد الرحمن بن ثابت بن ثوبان) as some have considered him to be reliable and others have considered him to be weak. The hadith is also corroborated through some other routes.
The hadith has been classed as Saheeh by al-Albani in Saheeh al-Jaami’. Zubair Ali Zai has classed it as Hasan in his grading of Abu Dawud. Ahmad Shakir has classed it as Saheeh in his grading of Musnad Ahmad. Dhahabi has classed it as as Hasan or Saheeh in Siyar A‘laam an-Nubala. Other scholars have also leaned towards it being authentic.
It has been graded as Hasan by al-Arnaa’oot in his grading of Zaad al-Ma'aad, although conversely he leans towards it being weak in his grading of Musnad Ahmad and Abu Dawud. Some other scholars have also leaned towards it being weak.
The content of the hadith seems acceptable in its meaning and there are other authentic reports which convey essentially the same things. Below I will cite a few the verses of the Quran and some Hadith from Saheeh Bukhari which corroborate parts of the hadith in the question:
I have been sent ahead of the Hour
بعثت أنا والساعة كهاتين
I have been sent and the Hour (is at hand) as these two (fingers)
— Bukhari
with the sword so that Allah will be worshipped alone
أمرت أن أقاتل الناس حتى يقولوا لا إله إلا الله فمن قال لا إله إلا الله، فقد عصم مني نفسه وماله، إلا بحقه
I have been ordered to fight with the people till they say, 'None has the right to be worshipped but Allah,' and whoever says, 'None has the right to be worshipped but Allah,' his life and property will be saved by me except for Islamic law
— Bukhari
Ibn Kathir has cited the hadith of being sent with the sword in the explanation of the following verse:
وأنزلنا الحديد فيه بأس شديد
And We sent down iron, wherein is great military might
— Quran 57:25
my provision has been placed in the shade of my spear
The provision may refer to the spoils of war:
فكلوا مما غنمتم حلالا طيبا
So consume what you have taken of war booty [as being] lawful and good
— Quran 8:69
أحلت لي الغنائم
War Booty has been made legal for me.
— Bukhari
Or it may refer to Paradise, since it is often referred to as provision in the Quran (like 22:50):
الجنة تحت ظلال السيوف
Paradise is under the shades of swords
— Bukhari
humiliation has been decreed for those who go against my command
This may refer to the disbelievers:
إن الذين يحادون الله ورسوله أولئك في الأذلين
Indeed, the ones who oppose Allah and His Messenger - those will be among the most humbled.
— Quran 58:20
Or it may refer to the believers who persist in going against the Prophet's teachings:
فليحذر الذين يخالفون عن أمره أن تصيبهم فتنة أو يصيبهم عذاب أليم
So let those beware who dissent from the Prophet's order, lest fitnah strike them or a painful punishment.
— Quran 24:63
whoever imitates a people is one of them
This is condemnation of imitation of disbelievers, and that is also evident in authentic ahadith such as:
خالفوا المشركين، وفروا اللحى، وأحفوا الشوارب
Do the opposite of what the pagans do. Keep the beards and cut the moustaches short.
— Bukhari
إن اليهود والنصارى لا يصبغون فخالفوهم
Jews and Christians do not dye their hair so you should do the opposite of what they do.
— Bukhari
Other References: