Windows Vista Forums

While loop search and count words.
  1. #1


    techjohnny Guest

    While loop search and count words.

    I have a bat file called "asbmon.bat that displays text "active." I
    need to be able to run this program continuously and count the number
    of times "active" is displayed. Is this something powershell can do?



    Thanks,

    --TJ

      My System SpecsSystem Spec

  2. #2


    RichS [MVP] Guest

    RE: While loop search and count words.

    $count = 0
    while ($true) {./asbmon.bat; $count++; $count}

    would do what you want I think

    --
    Richard Siddaway
    All scripts are supplied "as is" and with no warranty
    PowerShell MVP
    Blog: http://richardsiddaway.spaces.live.com/
    PowerShell User Group: http://www.get-psuguk.org.uk


    "techjohnny@xxxxxx" wrote:

    > I have a bat file called "asbmon.bat that displays text "active." I
    > need to be able to run this program continuously and count the number
    > of times "active" is displayed. Is this something powershell can do?
    >
    > Thanks,
    >
    > --TJ
    >

      My System SpecsSystem Spec

  3. #3


    Kiron Guest

    Re: While loop search and count words.

    Try something like this (use Ctrl-C to halt):

    &{
    while (1) {
    cls
    $i = 0
    .\asbmon | % {if ($_ -match 'active') {$i++}}
    "$i active"
    sleep -m 250
    }
    }

    --
    Kiron

      My System SpecsSystem Spec

  4. #4


    techjohnny Guest

    Re: While loop search and count words.

    On Apr 18, 1:38 pm, "Kiron" <Ki...@xxxxxx> wrote:

    > Try something like this (use Ctrl-C to halt):
    >
    > &{
    > while (1) {
    > cls
    > $i = 0
    > .\asbmon | % {if ($_ -match 'active') {$i++}}
    > "$i active"
    > sleep -m 250
    > }
    >
    > }
    >
    > --
    > Kiron
    This is actually perfect. I would like to run this from a script, but
    when I copy-n-paste into text file and run it, it tries to open it
    with notepad and doesn't execute script.

      My System SpecsSystem Spec

  5. #5


    techjohnny Guest

    Re: While loop search and count words.

    On Apr 18, 1:38 pm, "Kiron" <Ki...@xxxxxx> wrote:

    > Try something like this (use Ctrl-C to halt):
    >
    > &{
    > while (1) {
    > cls
    > $i = 0
    > .\asbmon | % {if ($_ -match 'active') {$i++}}
    > "$i active"
    > sleep -m 250
    > }
    >
    > }
    >
    > --
    > Kiron
    nevermind, just renamed it to .ps1

      My System SpecsSystem Spec

  6. #6


    techjohnny Guest

    Re: While loop search and count words.

    On Apr 18, 3:08 pm, "techjoh...@xxxxxx" <techjoh...@xxxxxx>
    wrote:

    > On Apr 18, 1:38 pm, "Kiron" <Ki...@xxxxxx> wrote:
    >

    > > Try something like this (use Ctrl-C to halt):
    >

    > > &{
    > > while (1) {
    > > cls
    > > $i = 0
    > > .\asbmon | % {if ($_ -match 'active') {$i++}}
    > > "$i active"
    > > sleep -m 250
    > > }
    >

    > > }
    >

    > > --
    > > Kiron
    >
    > nevermind, just renamed it to .ps1
    How can I extend this to send an e-mail alert if the match number is
    above 10?

    Thanks,

    --TJ

      My System SpecsSystem Spec

  7. #7


    Joel (Jaykul) Bennett Guest

    Re: While loop search and count words.

    That's a whole 'nother thread, but there's a script on the repository
    for sending email via SMTP ... it has a few extra things in it that
    relate to gmail specifically, but it's here: http://powershellcentral.com/scripts/180

    all you would need to do is, instead of the "$i active", do:

    if($i -gt 10) {
    Send-SmtpMessage "YOU@xxxxxx" "There are $i of them active!"
    "Remember, don't get them wet! ... and lots of other useful
    information can go here..."
    }

      My System SpecsSystem Spec

  8. #8


    techjohnny Guest

    Re: While loop search and count words.

    On Apr 18, 9:44 pm, "Joel (Jaykul) Bennett" <Jay...@xxxxxx>
    wrote:

    > That's a whole 'nother thread, but there's a script on the repository
    > for sending email via SMTP ... it has a few extra things in it that
    > relate to gmail specifically, but it's here:http://powershellcentral.com/scripts/180
    >
    > all you would need to do is, instead of the "$i active", do:
    >
    > if($i -gt 10) {
    > Send-SmtpMessage "Y...@xxxxxx" "There are $i of them active!"
    > "Remember, don't get them wet! ... and lots of other useful
    > information can go here..."
    >
    > }
    Perfect, but I'm using "Send-SmtpMail"

    --TJ

      My System SpecsSystem Spec

  9. #9


    techjohnny Guest

    Re: While loop search and count words.

    On Apr 21, 9:35 am, "techjoh...@xxxxxx" <techjoh...@xxxxxx>
    wrote:

    > On Apr 18, 9:44 pm, "Joel (Jaykul) Bennett" <Jay...@xxxxxx>
    > wrote:
    >

    > > That's a whole 'nother thread, but there's a script on the repository
    > > for sending email via SMTP ... it has a few extra things in it that
    > > relate to gmail specifically, but it's here:http://powershellcentral.com/scripts/180
    >

    > > all you would need to do is, instead of the "$i active", do:
    >

    > > if($i -gt 10) {
    > > Send-SmtpMessage "Y...@xxxxxx" "There are $i of them active!"
    > > "Remember, don't get them wet! ... and lots of other useful
    > > information can go here..."
    >

    > > }
    >
    > Perfect, but I'm using "Send-SmtpMail"
    >
    > --TJ
    OK. The programming that runs this query request a password, I can
    specify the username from the command line, but it requires me to
    enter the password, so how can I automate the input of the password
    (which is probably not recommended, but need it)?

    Thanks,

    TJ

      My System SpecsSystem Spec

While loop search and count words. problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get-Help butchers words Larry__Weiss PowerShell 5 14 Mar 2010
for ... loop through file collection instead of for each ... loop Ranah van Rijswijk VB Script 2 21 Feb 2010
Search misses words that are in Outlook email gahoman Vista General 3 31 Aug 2008
search for words or phrases in vista mabola2 Vista file management 1 17 Aug 2007
Vista words update: No of words 69! John Jay Smith Vista General 2 29 Jul 2006