Mishkat al-Masabih 1323
Jabir said :
God’s Messenger used to teach us how to ask God’s guidance about matters just as he used to teach as a sura of the Qur’an, saying: When any of you intends to do something he should pray two rak'as which are not compulsory, then say, “O God, I ask Thy guidance by Thy knowledge, I ask Thee for power by Thy power, and I ask Thee out of Thy great abundance, for Thou hast power and I have none, Thou knowest and I did not, and Thou art the One who is aware of the unseen. O God, if Thou knowest that this matter is good for me regarding my religion, my livelihood, and my future wellbeing (or he said, “my affairs in this world and the next”), ordain it for me and make it easy for me, then bless me in it. But if Thou knowest that this matter is bad for me regarding my religion, my livelihood, and my future wellbeing (or he said, “my affairs in this world and the next”), turn it away from me, turn me away from it, ordain good for me wherever it is, then make me pleased with it.” He said that he should name what he required. 

Bukhari transmitted it.
عَنْ جَابِرِ بْنِ عَبْدِ اللَّهِ قَالَ: كَانَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ يُعَلِّمُنَا الِاسْتِخَارَةَ فِي الْأُمُورِ كَمَا يُعَلِّمُنَا السُّورَةَ مِنَ الْقُرْآنِ يَقُولُ: 
" إِذَا هَمَّ أَحَدُكُمْ بِالْأَمْرِ فَلْيَرْكَعْ رَكْعَتَيْنِ مِنْ غَيْرِ الْفَرِيضَةِ ثُمَّ لْيَقُلْ: اللَّهُمَّ إِنِّي أَسْتَخِيرُكَ بِعِلْمِكَ وَأَسْتَقْدِرُكَ بِقُدْرَتِكَ وَأَسْأَلُكَ مِنْ فَضْلِكَ الْعَظِيمِ فَإِنَّك تَقْدِرُ وَلَا أقدر وَتعلم وَلَا أعلم وَأَنت علام الغيوب اللَّهُمَّ إِنَّ كُنْتَ تَعْلَمُ أَنَّ هَذَا الْأَمْرَ خَيْرٌ لِي فِي دِينِي وَمَعَاشِي وَعَاقِبَةِ أَمْرِي - أوقال فِي عَاجِلِ أَمْرِي وَآجِلِهِ - فَاقْدُرْهُ لِي وَيَسِّرْهُ لِي ثُمَّ بَارِكْ لِي فِيهِ وَإِنْ كُنْتَ تَعْلَمُ أَنَّ هَذَا الْأَمْرَ شَرٌّ لِي فِي دِينِي وَمَعَاشِي وَعَاقِبَةِ أَمْرِي - أَوْ قَالَ فِي عَاجِلِ أَمْرِي وَآجِلِهِ - فَاصْرِفْهُ عَنِّي وَاصْرِفْنِي عَنْهُ وَاقَدُرْ لِيَ الْخَيْرَ حَيْثُ كَانَ ثُمَّ أَرْضِنِي بِهِ ". قَالَ: «ويسمي حَاجته» . رَوَاهُ البُخَارِيّ