How Much Did Gandalf Know?

Being a Maiar, he should have seen the foundation of the world. How much does he know about what was, is, and will be, while "embodied" in Middle-earth?

Read the "Shadows in the Dark" chapter of FOTR to hear the answer from the horse's mouth: in the book Gandalf tells Frodo how he slowly pieced together the truth about the Ring. More importantly, read "The Quest for Erebor" in Unfinished Tales, which is Gandalf talking after the Quest is over. Once his task is achieved, he actually "remembers" a great deal more of what he knew as a Maia.

While Gandalf was on Middle-earth, his powers were curtailed; he could sense where the future might go, sometimes, and have premonitions, but he certainly didn't know Sauron would be destroyed; he didn't even know the Ring had been found until he did a good deal of research to determine what king Other examples of Gandalf being in the dark about the future:In the "Last Debate" chapter of ROTK, he tells the Captains of the West that he thinks the Ringbearer might achieve his quest, and they might aid him by attacking Mordor and drawing Sauron's forces away, but they very likely would die without ever knowing if the Quest had succeeded. Of the time when the White Council drove Sauron from Dol Guldur and Sauron secretly returned to Mordor, Gandalf said, of a ring it was.

"But he was always ahead of us in his plans. I must confess that I thought he really had retreated again, and that we might have another spell of watchful peace." That comes from the UT chapter I mentioned, as does this:

of a ring it was.

"... Did you plan all this, then, Gandalf? If not, why did you lead Thorin Oakenshield to such an unlikely door? To find the Ring and bring it far away into the West for hiding, and then to choose the Ringbearer-- and to restore the Mountain Kingdom as a mere deed by the way: was not that your design?"
... "I do not know the answer. For I have changed since those days, and I am no longer trammelled by the burden of Middle-earth as I was then. In those days I should have answered you with words like those I used to Frodo, only last year in the spring. Only last year! But such measures are meaningless. In that far distant time I said to a small and frightened Hobbit: Bilbo was meant to find the Ring, and not by its maker, and you therefore were meant to bear it. And I might have added: and I was meant to guide you both to those points.
"To do that I used in my waking mind only such means as were allowed to me, doing what lay to my hand according to such resources as I had. But what I knew in my heart, or knew before I stepped onto these grey shores: that is another matter. Olórin I was in the West that is forgotten, and only to those who are there shall I speak more openly."

He is being vague, I note, but his "waking mind" is the one he has on Middle-earth. At some gut level he knew more than he's letting on, but even the Valar themselves didn't know Morgoth would destroy the Trees, that the Noldor would revolt, the petition of Ëarendil, the rebellion of Númenor, and all the events of the Silmarillion-- how then could Gandalf, a lesser Maia, bound into a weakened form in Middle-earth, deceived even by Saruman whom he knew well and was less powerful, know for certain Sauron would be defeated? He did not.

All Ganalf was doing is getting to know people all over Middle-earth, finding allies, and making friendships, then capitalizing on them. This was key. He had to know the character of Aragorn, Bilbo, Frodo, Denethor, Faramir, Treebeard in order to predict where they'd go, how far to trust them; his slip with Saruman was a rare near-fatal mistake. Usually Gandalf was encouraging a Hobbit here or a Ranger there, having the sense to see that Minas Tirith would need Rohan and Rohan would not be able to come without defeating Saruman, that Rohan would not defeat Saruman without help from the Huorns. And in the case of the latter, Gandalf was well-served by having earned Treebeard's trust such that he could call on the Ents at need. But he did not know he could call on the Huorns, until, halfway to Helm's Deep, Legolas spots them moving on Isengard-- and Gandalf goes charging off that way to catch up with Treebeard, seizing the "resource near to hand". Giving Aragorn the Palantir that was tossed down, which proved the key to Aragorn's victory, is another example, and grabbing Sam when Sam was eavesdropping is yet another. Gandalf was a master of improvisation, and in the end he tended to seek and rely on other who improvised, more even than upon the Wise, to achieve his goals: Bilbo, Frodo, Sam, Aragorn, Faramir, Théoden once he was restored to himself. That's why he kept grabbing Tooks and Brandybucks: Merry and Pippin were weak, but they could be counted on to grab and seize opportunities the way Gandalf did.

I think Gandalf's main skill of premonition lies in his understanding of hearts. Read the book closely, and watch how often he is reading others, guessing what they'll do, and giving them what they need to make choices he feels are strategically necessary (but he can't predict how they will turn out; he is guessing). As Gimli said, "you could not compel." He could only try to persuade.