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 can be found in both Super Mario Galaxy and Super Mario Galaxy 2. It is used in Rolling Green Galaxy, Rolling Gizmo Galaxy and at the last part of the second Star mission in Melty Molten Galaxy in Super Mario Galaxy, and in the Rolling Masterpiece Galaxy and the Rolling Coaster Galaxy in Super Mario Galaxy 2. In the Purple Coin mission of Rolling Coaster Galaxy, there is a Purple Coin instead of a Power Star inside the ball and the ball is purple.
The player can control the Star Ball by first jumping on top of it and 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.
In all three appearances, 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.
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.
Additionally, the speed which Mario rolls affects the speed and the pitch of the background music being played.
 See also