def powershell(cmd, cwd=None, stdin=None, runas=None, shell=DEFAULT_SHELL, env=None, clean_env=False, template=None, rstrip=True, umask=None, output_loglevel='debug', quiet=False, timeout=None, reset_system_locale=True, ignore_retcode=False, saltenv='base', use_vt=False, password=None, depth=None, encode_cmd=False, **kwargs):
 if ('python_shell' in kwargs):
  python_shell = kwargs.pop('python_shell')
 else:
  python_shell = True
 cmd += ' | ConvertTo-JSON'
 if (depth is not None):
  cmd += ' -Depth {0}'.format(depth)
 if encode_cmd:
  log.debug("Encoding PowerShell command '{0}'".format(cmd))
  cmd_utf16 = cmd.decode('utf-8').encode('utf-16le')
  cmd = base64.standard_b64encode(cmd_utf16)
  encoded_cmd = True
 else:
  encoded_cmd = False
 response = run(cmd, cwd=cwd, stdin=stdin, runas=runas, shell='powershell', env=env, clean_env=clean_env, template=template, rstrip=rstrip, umask=umask, output_loglevel=output_loglevel, quiet=quiet, timeout=timeout, reset_system_locale=reset_system_locale, ignore_retcode=ignore_retcode, saltenv=saltenv, use_vt=use_vt, python_shell=python_shell, password=password, encoded_cmd=encoded_cmd, **kwargs)
 try:
  return json.loads(response)
 except Exception:
  log.error('Error converting PowerShell JSON return', exc_info=True)
  return {}

def powershell ( cmd , cwd = None , stdin = None , runas = None , shell = DEFAULT_SHELL , env = None , clean_env = False , template = None , rstrip = True , umask = None , output_loglevel = 'debug' , quiet = False , timeout = None , reset_system_locale = True , ignore_retcode = False , saltenv = 'base' , use_vt = False , password = None , depth = None , encode_cmd = False , ** kwargs ) : if ( 'python_shell' in kwargs ) : python_shell = kwargs . pop ( 'python_shell' ) else : python_shell = True cmd += ' | ConvertTo-JSON' if ( depth is not None ) : cmd += ' -Depth {0}' . format ( depth ) if encode_cmd : log . debug ( "Encoding PowerShell command '{0}'" . format ( cmd ) ) cmd_utf16 = cmd . decode ( 'utf-8' ) . encode ( 'utf-16le' ) cmd = base64 . standard_b64encode ( cmd_utf16 ) encoded_cmd = True else : encoded_cmd = False response = run ( cmd , cwd = cwd , stdin = stdin , runas = runas , shell = 'powershell' , env = env , clean_env = clean_env , template = template , rstrip = rstrip , umask = umask , output_loglevel = output_loglevel , quiet = quiet , timeout = timeout , reset_system_locale = reset_system_locale , ignore_retcode = ignore_retcode , saltenv = saltenv , use_vt = use_vt , python_shell = python_shell , password = password , encoded_cmd = encoded_cmd , ** kwargs ) try : return json . loads ( response ) except Exception : log . error ( 'Error converting PowerShell JSON return' , exc_info = True ) return { }
yaml: powershell execute a powershell command .