Great script, Thanks !
I had a few databases offline, so I did this to ignore them:
-- I added the "status" field check for SQL 2000 & 2005
SELECT name
FROM sysdatabases
WHERE name NOT IN ('master', 'model', 'msdb', 'tempdb')
and status <> 66048-- SQL2005 DB offline
and status <> 528-- SQL2000 DB offline