locked
Check other Browsers than Internet Explorer RRS feed

  • Question

  • Hello,

    I'm a beginner in Powershell scipt...

    For some reasons, I want to determinate what users in my company are using other browsers than Internet Explorer and export the result in a csv file. The script below is correctly running but if the users doesn't use chrome, firefox, safari or opera, the script returns this kind of information "username;Fcomputername;;date" and my file become uselessly bigger and bigger....

    I don't know how tell to the script that if get-process returns any information so, it will have to check the local processes again until it exists chrome, firefox, safari or opera processes and at this time to return this information into my csv file...

    SomeOne could help me please ? I thank you in advance...

    $date = Get-Date -Format "%d'/'%M'/'%y"

    while ($true)

    {

    $runningBrowsers = Get-Process -name "chrome","firefox","safari","opera" -ErrorAction SilentlyContinue |

                            Sort-Object -Unique processName |

                                Select-Object -ExpandProperty processName

    "$env:Username;$env:ComputerName;$($runningBrowsers -join ', ');$date." | out-File "\\x.x.x.x\share\Mschkbwr.csv" -Append

    sleep 60

    }

    Saturday, October 27, 2012 6:04 PM

Answers

  • Just put a condition on your Out-File:

    if ($runningBrowsers) { ... | Out-File ... -Append }


    Grant Ward, a.k.a. Bigteddy

    • Proposed as answer by stefan-iz Saturday, October 27, 2012 7:14 PM
    • Marked as answer by Fabiio_from_26 Saturday, October 27, 2012 7:34 PM
    Saturday, October 27, 2012 6:41 PM

All replies

  • Just put a condition on your Out-File:

    if ($runningBrowsers) { ... | Out-File ... -Append }


    Grant Ward, a.k.a. Bigteddy

    • Proposed as answer by stefan-iz Saturday, October 27, 2012 7:14 PM
    • Marked as answer by Fabiio_from_26 Saturday, October 27, 2012 7:34 PM
    Saturday, October 27, 2012 6:41 PM
  • So symply..... Thank a lot Bigteddy.

    Have a good night !

    Saturday, October 27, 2012 7:34 PM