Execute the desired powershell command and ensure that it returns data
    in JSON format and load that into python

def _pshell_json(cmd, cwd=None):
    '''
    Execute the desired powershell command and ensure that it returns data
    in JSON format and load that into python
    '''
    if 'convertto-json' not in cmd.lower():
        cmd = '{0} | ConvertTo-Json'.format(cmd)
    log.debug('PowerShell: %s', cmd)
    ret = __salt__['cmd.run_all'](cmd, shell='powershell', cwd=cwd)

    if 'pid' in ret:
        del ret['pid']

    if ret.get('stderr', ''):
        error = ret['stderr'].splitlines()[0]
        raise CommandExecutionError(error, info=ret)

    if 'retcode' not in ret or ret['retcode'] != 0:
        # run_all logs an error to log.error, fail hard back to the user
        raise CommandExecutionError(
            'Issue executing PowerShell {0}'.format(cmd), info=ret)

    # Sometimes Powershell returns an empty string, which isn't valid JSON
    if ret['stdout'] == '':
        ret['stdout'] = '{}'

    try:
        ret = salt.utils.json.loads(ret['stdout'], strict=False)
    except ValueError:
        raise CommandExecutionError(
            'No JSON results from PowerShell', info=ret)

    return ret