This script is meant to be run on the distributor in the distributor database as mentioned above.
I am using the sp_MSforeachDB stored procedure which takes a query as a parameter and runs it against each DB on the server. The SQL that is being run against each database is in the @command variable. That is the reason for the SQL in single quotes.
The ? will be replace by the database name as the sp_MSforeachDB cycles through each database on the server. Then the rest of the SQL will be ran in that database.
Sorry if that was not clear.