From the Super Mario Wiki
The Star Ball (also known as Rolling Ball) is a large, transparent, capsule-like ball with a Power Star in it that appears in both Super Mario Galaxy and Super Mario Galaxy 2. It is used in Rolling Green Galaxy, Rolling Gizmo Galaxy, and the last part of the second Star mission in Melty Molten Galaxy in Super Mario Galaxy; in Super Mario Galaxy 2, it is found in the Rolling Masterpiece Galaxy and the Rolling Coaster Galaxy. In the Purple Coin mission of Rolling Coaster Galaxy, there is a Purple Coin Ball which contains a Purple Coin instead of the usual Star, and is colored purple itself.
The player can control the Star Ball by first jumping on top of it, and then tilting the Wii Remote in the direction they wish to travel while trying to move at a steady pace. Once Mario is on the Star Ball, it is impossible for him to dismount it. Mario's objective is to ride the Star Ball into a hole marked by a yellow flag, which is similar to a golf hole. To get to the flag, Mario must bypass numerous challenging obstacles, including narrow ledges, enemies, and moving platforms. Additionally, the speed which Mario rolls affects the speed and the pitch of the background music being played.
Once Mario rolls the Star Ball into the ball-opener, the ball explodes, and the Power Star within is released. The Power Star moves itself to a flag pole found at the end of the course, where Mario must climb up in order to collect it.