Another PS StdOut

Started by spl, August 20, 2024, 12:01:36 PM

Previous topic - Next topic

spl

Checks status of Windows Defender, updates signature before checking. Pretty ugly output, but interesting to get the information from STDOut.
;Windows Defender Status
;save as ..\StdOut_Defender.wbt
;Stan Littlefield 8/20/2024
;==========================================================
Gosub udfs
args = $"if (!(Get-Module -ListAvailable -Name WindowsDefender)) { Install-Module -Name WindowsDefender -Scope CurrentUser -allowclobber -force }
Import-Module -Name WindowsDefender
Update-MpSignature
Get-MpComputerStatus -ErrorAction Continue
$"
cmd="Powershell"
msg='Windows Defender Status'

BoxOpen("Running...",cmd:" ":args:@LF:"PLEASE WAIT...MAY TAKE SOME TIME")
TimeDelay(2)
vals = Get_stdout()
vals = StrReplace(vals,'"','')
Message(msg,vals)
;optional - create output file with links, for further scraping
;FilePut("c:\temp\Defender.txt",vals)
Exit
;==========================================================
:udfs
#DefineSubroutine Get_stdout()
ObjectClrOption("useany","System")
objInfo = ObjectClrNew("System.Diagnostics.ProcessStartInfo")
Output=""
objInfo.FileName = cmd
objInfo.RedirectStandardError = ObjectType("BOOL",@TRUE)
objInfo.RedirectStandardOutput = ObjectType("BOOL",@TRUE)
objInfo.UseShellExecute = ObjectType("BOOL",@FALSE)
objInfo.CreateNoWindow = ObjectType("BOOL",@TRUE)
objInfo.Arguments = args
oProcess = ObjectClrNew("System.Diagnostics.Process")
oProcess.StartInfo = objInfo
BoxShut()
oProcess.Start()
oProcess.WaitForExit()
STDOUT = oProcess.StandardOutput.ReadToEnd()
STDERR = oProcess.StandardError.ReadToEnd()
Output = Output:STDOUT:@CRLF
If STDERR<>""
   Output = Output:"STDERR:":STDERR:@CRLF
Endif
oProcess = 0
objInfo = 0

Return (Output)
#EndSubroutine
Return
;==========================================================

Stan - formerly stanl [ex-Pundit]

spl

This will be the last StdOut PS. Did want to illustrate combining 2 technologies.
Stan - formerly stanl [ex-Pundit]