DX Infrastructure Manager

Expand all | Collapse all

Logmon - command with powershell

  • 1.  Logmon - command with powershell

    Posted 09-14-2021 09:02 AM
    Edited by Philippe-Andre Trottier 09-14-2021 09:06 AM

    Hey everyone. I am trying to run a powershell script with logmon (command mode) and get the output of that script with a watcher.   Right now it doesn't look like a success (the script doesn't seem to run or the output is not catched by the watcher.

    The script is pretty simple: I do a invoke-webrequest on a webpage and it return either an output  OK or ERROR.  I don't use URL response for various reasons...

    So here's my configuration from IM:  Does it seem ok?



    Here is the script:

    try
    {
    $Response = Invoke-WebRequest -Uri "www.google.ca"
    # This will only execute if the Invoke-WebRequest is successful.
    $StatusCode = $Response.StatusCode
    }
    catch
    {
    $StatusCode = $_.Exception.Response.StatusCode.value__
    }

    if ($StatusCode -like '404')
    {
    echo OK
    }
    Else
    {
    $StatusCode
    echo ERROR
    }



    ------------------------------
    Philippe-Andre Trottier
    [JobTitle]
    [CompanyName]
    Montreal,Quebec
    ------------------------------


  • 2.  RE: Logmon - command with powershell

    Posted 09-14-2021 09:12 AM
    Set the log level to 5 on logmon and run the profile - should log the errors there

    Have you verified that the account running the probe can run powershell?

    Have you tried creating a cmd/bat file that echos "OK" to verify that everything else works ok?


  • 3.  RE: Logmon - command with powershell

    Posted 2 days ago
    Edited by Steve B 2 days ago
    You shouldn't even need a batch file - just paste the powershell.exe line directly into logmon:

    powershell -ExecutionPolicy Bypass -file "E:\Nimsoft\custom_scripts\check_shares.ps1"




  • 4.  RE: Logmon - command with powershell

    Posted 09-14-2021 10:14 AM
    Looks like it works with a batch file. I've created a batch to execute the PS1 file and nimsoft accepts it. It works now.

    thanks !

    ------------------------------
    Philippe-Andre Trottier
    [JobTitle]
    [CompanyName]
    Montreal,Quebec
    ------------------------------



  • 5.  RE: Logmon - command with powershell

    Posted 3 days ago
    Hi Philippe-Andre,

    this is exactly what we are doing: start the batch file to start powershell. Just for the sake of the next man looking at this, here is a sample Batch file:

    @C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '.\nameOfPowershellScript.ps1'"

    where the batch and script file are in the same folder.