Problem processing quotes by T-SQL during Job creation
Your code is nearly there, just change:

'...
WHERE m.mirroring_role_desc &lt;&gt; 'MIRROR'


to

'...
WHERE m.mirroring_role_desc &lt;&gt; ''MIRROR''




Jonathan Fite also mentions this nice QUOTENAME() solution in the comments below:

'...
WHERE m.mirroring_role_desc &lt;&gt; ' + QUOTENAME(MIRROR, '''')