powershellsymantec

How do I run a Symantec Endpoint Protection scan via Start-Job with PowerShell?


I'm trying to run an antivirus scan via PowerShell as a background process.

My code:

$arg1 = "/c"
$arg2 = "/ScanAllDrives"
$logFile = "/LOGFILE='C:\Users\user\AppData\Local\Symantec\Symantec Endpoint Protection\Logs\test.log'"

Start-Job -ScriptBlock {"C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\12.1.7004.6500.105\Bin\DoScan.exe"} -ArgumentList "$arg1 $arg2 $logFile

The job runs for a second then stops. Get-Job shows it has completed, but it has not given the runtime and lack of log file.

It works fine when I run it from the PowerShell console as follows:

& "C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\12.1.7004.6500.105\Bin\DoScan.exe" /c /ScanAllDrives

Any idea why this won't run in the background? I've tried adding the args directly into the scriptblock but it doesn't seem to like that at all. I'm not finding it easy to see why it completes as the background job doesn't produce any output.


Solution

  • Per your comment, when investigating the result of a PowerShell job, use the Receive-Job cmdlet with the ID of the job to see the resultant output. This will likely help you troubleshoot further.

    I think the following revised code will work, but I don't have SEP installed locally so can't perform a complete test (but it did work with a substitute .exe):

    $arg1 = '/c'
    $arg2 = '/ScanAllDrives'
    $logFile = '/LOGFILE="C:\Users\user\AppData\Local\Symantec\Symantec Endpoint Protection\Logs\test.log"'
    
    Start-Job -ScriptBlock {& "C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\12.1.7004.6500.105\Bin\DoScan.exe" $Args[0] $Args[1] $Args[2]} -ArgumentList $arg1, $arg2, $logFile
    

    Explanation: