def _pshell(cmd, cwd=None, json_depth=2):
 if (u'convertto-json' not in cmd.lower()):
  cmd = u'{0} | ConvertTo-Json -Depth {1}'.format(cmd, json_depth)
 log.debug(u'DSC: {0}'.format(cmd))
 results = __salt__[u'cmd.run_all'](cmd, shell=u'powershell', cwd=cwd, python_shell=True)
 if (u'pid' in results):
  del results[u'pid']
 if ((u'retcode' not in results) or (results[u'retcode'] != 0)):
  raise CommandExecutionError(u'Issue executing powershell {0}'.format(cmd), info=results)
 try:
  ret = json.loads(results[u'stdout'], strict=False)
 except ValueError:
  raise CommandExecutionError(u'No JSON results from powershell', info=results)
 return ret

def _pshell ( cmd , cwd = None , json_depth = 2 ) : if ( u'convertto-json' not in cmd . lower ( ) ) : cmd = u'{0} | ConvertTo-Json -Depth {1}' . format ( cmd , json_depth ) log . debug ( u'DSC: {0}' . format ( cmd ) ) results = __salt__ [ u'cmd.run_all' ] ( cmd , shell = u'powershell' , cwd = cwd , python_shell = True ) if ( u'pid' in results ) : del results [ u'pid' ] if ( ( u'retcode' not in results ) or ( results [ u'retcode' ] != 0 ) ) : raise CommandExecutionError ( u'Issue executing powershell {0}' . format ( cmd ) , info = results ) try : ret = json . loads ( results [ u'stdout' ] , strict = False ) except ValueError : raise CommandExecutionError ( u'No JSON results from powershell' , info = results ) return ret
execute the desired powershell command and ensure that it returns data in json format and load that into python .