The Messenger of Allah ﷺ used to teach us the prayer for guidance just as he would teach us a surah from the Quran. He would say, "When one of you intends to undertake a matter, let him pray two units of prayer apart from the obligatory ones, then say, 'O Allah, I seek Your guidance through Your knowledge, and I seek Your power through Your might, and I ask You from Your immense bounty. For You have power and I have none, and You know and I do not, and You are the Knower of all that is hidden. O Allah, if You know that this matter,'" and he names it, "'whatever it may be, is good for me in my religion, my livelihood, and the outcome of my affairs, or good for me in the immediate and distant future, then decree it for me, make it easy for me, and bless it for me. And if You know,'" he repeats the same words as in the first instance, "'that it is bad for me, then turn it away from me and turn me away from it, and decree for me what is good wherever it may be, then make me content with it.'"
حدثنا أحمد بن يوسف السلمي حدثنا خالد بن مخلد حدثنا عبد الرحمن بن أبي الموالي قال سمعت محمد بن المنكدر يحدث
كان رسول الله ﷺ يعلمنا الاستخارة كما يعلمنا السورة من القرآن يقول إذا هم أحدكم بالأمر فليركع ركعتين من غير الفريضة ثم ليقل اللهم إني أستخيرك بعلمك وأستقدرك بقدرتك وأسألك من فضلك العظيم فإنك تقدر ولا أقدر وتعلم ولا أعلم وأنت علام الغيوب اللهم إن كنت تعلم هذا الأمر فيسميه ما كان من شيء خيرا لي في ديني ومعاشي وعاقبة أمري أو خيرا لي في عاجل أمري وآجله فاقدره لي ويسره لي وبارك لي فيه وإن كنت تعلم يقول مثل ما قال في المرة الأولى وإن كان شرا لي فاصرفه عني واصرفني عنه واقدر لي الخير حيثما كان ثم رضني به
Bukhari narrated it in tahajjud, chapter on what has been said about voluntary prayers being performed two units at a time, hadith no. 1162, and others narrated it from the hadith of Abdul-Rahman, as mentioned. Sourcing: