'Return value escaped for use in PowerShell command.'

def _escape(self, value, include_vars=False):

    subs = [('\n', '`n'), ('\r', '`r'), (' DCTB ', '`t'), ('\x07', '`a'), ('\x08', '`b'), ('\x0c', '`f'), ('\x0b', '`v'), ('"', '`"'), ("'", "`'"), ('`', '``'), ('\x00', '`0')]
    if include_vars:
        subs.append(('$', '`$'))
    pattern = '|'.join((('(%s)' % re.escape(p)) for (p, s) in subs))
    substs = [s for (p, s) in subs]
    def replace(m):
        return substs[(m.lastindex - 1)]
    return re.sub(pattern, replace, value)
