if encode_cmd:
        # Convert the cmd to UTF-16LE without a BOM and base64 encode.
        # Just base64 encoding UTF-8 or including a BOM is not valid.
        log.debug('Encoding PowerShell command \'%s\'', cmd)
        cmd_utf16 = cmd.decode('utf-8').encode('utf-16le')