I have often used undocumented stored procedures, such as sp_msForEachTable and sp_msForEachDatabase, for quickly scripting out admin tasks. However, their usage is not documented in Books Online, so it can sometimes be very much a hunt and peck exercise.
The following articles should help you to learn more about these stored procedures, including their syntax, benefits, and pitfalls:
SQL Server 7.0 Useful Undocumented Store... SQL Server 2000 Useful Undocumented Stor... Of course, use undocumented stored procedures with caution, and never in production code. Remember that these procedures are undocumented for a reason — their behavior could change in a future version or service pack, or they could disappear completely. So, you should be prepared to test all of your scripts and applications that rely on these procedures, every time you make any kind of change to your SQL Server installation(s).