Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Optimize the output of pscmd
#3
Use this function instead of PsCmd.

Function PsCmd3
Code:
Copy      Help
;/
function# $commands [$cl] [str&output] [flags] ;;flags: 1 UTF-8 output, 2 ANSI output

;Executes PowerShell script stored in a variable or macro.
;Waits and returns powershell.exe's return value.

;commands - one or more PowerShell commands.
;;;QM 2.3.5. Can be macro, like "macro:MacroName". Gets whole text, or text that follows #ret line. Ignores first line if it looks like macro options ( /...).
;;;QM 2.3.5. If "", gets caller's text that follows #ret line.
;cl - additional powershell.exe command line arguments.
;output - variable that receives output text. If omitted or 0, displays the text in QM output.
;flags - output text encoding. See example.

;REMARKS
;Uses a temporary file and command line -File to pass it to powershell.exe. Also adds command line -ExecutionPolicy Bypass.
;Error if powershell.exe does not exist. PowerShell is available on Windows 7/2008/+, and can be downloaded for some older Windows versions.

;See also: <PsFile>

;EXAMPLES
;PsCmd3 "get-date"

;str code=
;;get-process
;PsCmd3 code "" _s
;out _s

;PsCmd3 "" "" 0 1
;#ret
;[Console]::OutputEncoding=[System.Text.Encoding]::UTF8
;Write-Host "test ąčę αβγ"


#exe addtextof "<script>"
#opt nowarnings 1
opt noerrorshere 1

Scripting_GetCode commands _s

__TempFile tf.Init("ps1")
if(_unicode) str s.from("[0xEF][0xBB][0xBF]" commands); s.setfile(tf)
else _s=commands; _s.setfile(tf)

s.format("%s -ExecutionPolicy Bypass -File ''%s''" cl tf)

ret sub.PsRunCL(s output flags)


#sub PsRunCL
function# $cl [str&output] [flags]

opt noerrorshere 1

str ps.searchpath("powershell.exe"); if(!ps.len) end "PowerShell not installed"
str s.format("%s %s" ps cl)
if(!&output) int print=1; str so; &output=so
int enc=0; if(flags&1) enc=0x800; else if(flags&2) enc=0x400
int r=RunConsole2(s output 0 enc)
output.trim("[]")
if(print and output.len) out output
ret r


Messages In This Thread
Optimize the output of pscmd - by win - 05-05-2019, 11:48 PM
RE: Optimize the output of pscmd - by Gintaras - 05-06-2019, 03:43 AM
RE: Optimize the output of pscmd - by Gintaras - 05-06-2019, 04:44 AM
RE: Optimize the output of pscmd - by win - 05-06-2019, 04:57 AM
RE: Optimize the output of pscmd - by Gintaras - 05-06-2019, 06:15 AM
RE: Optimize the output of pscmd - by win - 05-06-2019, 07:21 AM
RE: Optimize the output of pscmd - by Gintaras - 05-06-2019, 07:35 AM
RE: Optimize the output of pscmd - by win - 05-06-2019, 07:41 AM
RE: Optimize the output of pscmd - by Gintaras - 05-06-2019, 07:55 AM
RE: Optimize the output of pscmd - by win - 05-06-2019, 08:05 AM
RE: Optimize the output of pscmd - by Gintaras - 05-06-2019, 08:12 AM
RE: Optimize the output of pscmd - by win - 05-06-2019, 08:15 AM
RE: Optimize the output of pscmd - by Gintaras - 05-06-2019, 08:26 AM
RE: Optimize the output of pscmd - by win - 05-06-2019, 09:02 AM
RE: Optimize the output of pscmd - by win - 05-07-2019, 11:48 PM
RE: Optimize the output of pscmd - by win - 05-08-2019, 03:54 AM
RE: Optimize the output of pscmd - by Gintaras - 05-08-2019, 04:25 AM
RE: Optimize the output of pscmd - by win - 05-08-2019, 05:42 AM
RE: Optimize the output of pscmd - by win - 05-08-2019, 09:37 AM
RE: Optimize the output of pscmd - by win - 05-08-2019, 12:51 PM
RE: Optimize the output of pscmd - by Gintaras - 05-08-2019, 01:05 PM
RE: Optimize the output of pscmd - by win - 05-08-2019, 01:17 PM
RE: Optimize the output of pscmd - by Kevin - 05-09-2019, 01:19 AM
RE: Optimize the output of pscmd - by win - 05-09-2019, 01:36 AM
RE: Optimize the output of pscmd - by Kevin - 05-09-2019, 01:40 AM
RE: Optimize the output of pscmd - by win - 05-09-2019, 01:43 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)