Answered Porcesses Read and Allert.

  • Friday, December 14, 2012 12:25 AM
     
     

    Hello all,

    I`m looking to build a small script that will do the following :

    1. Read the Processes

    2. If the"xxx" process is not in the list, send an alert mail to "xxx"

    3. Try to Start the service.

    I got the part with reading the processes but then...nothing.

    Can anyone help?

    Has to work on a 64bit Win 2008 R2 and Exchange email alert.

    Thank you.

All Replies

  • Friday, December 14, 2012 12:28 AM
    Moderator
     
     
    Can you post what you have so far? 

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Friday, December 14, 2012 1:20 AM
     
      Has Code

    Hi mjolinor,

    I`m the same person, different username.

    This is what I got until now. I`m trying to get the part with checking the service for the one that I want.

    $strComputer = "..." 
     
    $colItems = get-wmiobject -class "Win32_Process" -namespace "root\CIMV2" -computername $strComputer 
     
    foreach ($objItem in $colItems) { 
          write-host "Caption: " $objItem.Caption 
          write-host "User name: " $objItem.UserName
          write-host "Command Line: " $objItem.CommandLine 
          write-host "Creation Class Name: " $objItem.CreationClassName
          write-host "CS Creation Class Name: " $objItem.CSCreationClassName 
          write-host "CS Name: " $objItem.CSName 
          write-host "Description: " $objItem.Description 
          write-host "Executable Path: " $objItem.ExecutablePath 
          write-host "Execution State: " $objItem.ExecutionState 
          write-host "Name: " $objItem.Name
          write-host "Process ID: " $objItem.ProcessId


    • Edited by Potter Daniel Friday, December 14, 2012 1:21 AM changed content
    •  
  • Friday, December 14, 2012 3:59 AM
     
     

    The code posted does not check services it queries processes.

    The code is mostly unnecessary as the following will do exactly the same thing:

    Get-WmiObject Win32_Process | Format-List -Property UserName,CommandLine,CreationClassName,CSCreationClassName,CSName

    I didn't put all of the properties you had in but you get the idea.

    YOU need to write a script that has some logic in it such as: What is teh logic that you want to inplement to detect a service.

    Services are Win32_Service

    gwmi win32_service -filter "name='xxx' AND State='Stopped'" -computer mypc1

    Now you can see all 'xxx' services that are stopped.

    I knwo we haveposted this for you before more thatn once.  YOU keep asking the same question.  Please go  to the 'Learn' menu items and take some time to learn the basics of PowerShell.  There are numerous examples of testing services that are almost identical to your question.

    Here are 92 scripts showing how to manage services using various scripting methods.

    http://gallery.technet.microsoft.com/scriptcenter/site/search?f%5B0%5D.Type=RootCategory&f%5B0%5D.Value=operatingsystem&f%5B0%5D.Text=Operating%20System&f%5B1%5D.Type=SubCategory&f%5B1%5D.Value=services&f%5B1%5D.Text=Services

    One of these will get you closer that just guessing.


    ¯\_(ツ)_/¯

  • Friday, December 14, 2012 4:11 AM
    Moderator
     
     Answered Has Code

    I'll take a stab at #2

    $email = @{
                To       = 'you@work.com'
                From     = 'your_computer@work.com'
                Subject  = 'Sanity Check'
                Body     = 'You do not have a PowerShell ISE open.'
                SMTPServer = 'mysmtprelay@work.com'  
               }
    if (-not
            (gwmi win32_process -Filter "name = 'powershell_ise.exe'")
        )
             {Send-MailMessage @email}

    Not tested, but I think that should work.

    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Monday, December 17, 2012 10:14 PM
     
     

    Hi jrv, I`m sorry but you are confusing me with someone else. I never asked about this or any other services or processes.

    It appears that I haven`t explained what I`m after.

    A script that searches throught the running services and looks for a speciffic one. If it`s not there I want it to run a file that will start that process, if it`s running just move on.

    mjolinor, thank you. I can`t test it yet but I will let you know if it works or not as soon as I can.