5 Replies Latest reply on Oct 16, 2018 8:08 AM by Sai Ram

    PowerShell script to start a workflow, if the workflow is not running.

    Sai Ram Seasoned Veteran

      Hello All,

       

      I've a scenario. I need to check a workflow status and if it is Stopped/Aborted/completed it needs to be started. this process has to be checked once every 5 mins. So, when the server is up, the process runs all the time(we set a realtime workflow). But, when the server goes down, the powershell script should check once in every 2-5 mins and when the server is up and then start/trigger the workflow from the script using pmcmd command as given below. I'm not much in to powershell scripting, if any of you can help me a small script which can do this process that would be great.

       

      the pmcmd command which can trigger from command line script is given below:

      pmcmd startworkflow -sv integration_service -d domain_name -u username -p password -usd userdomain -f "folder_name" workflow_name

       

      Thank you,

      SaiRam.

        • 1. Re: PowerShell script to start a workflow, if the workflow is not running.
          Nico Heinze Guru

          I'm no experienced PowerShell author either. But I am sure you will find plenty of examples for PowerShell scripts with an "eternal loop" on the web via e.g. Google. I'm just too busy to do that myself.

           

          Regards,

          Nico

          • 2. Re: PowerShell script to start a workflow, if the workflow is not running.
            Ninko Kovachevich New Member

            Perhaps instead of PowerShell script you can create another workflow, scheduled to run every 5 minutes. This workflow will execute pmcmd scheduleworkflow (startworkflow if it is real-time and has no scheduler) command, without checking the status.

             

            Regards,

            Ninko

            • 3. Re: PowerShell script to start a workflow, if the workflow is not running.
              Nico Heinze Guru

              We have discussed similar approaches like your suggestion, Ninko, numerous times, and we always found one big disadvantage: if the second workflow (the "watchdog") fails to work for whatever reasons, it needs to be restarted manually.

              So finally we always ended in building a script (or batch file or whatever) to perform this task; this way we could at least be sure that the "entity" we want to monitor (be it a single workflow or the whole Informatica domain) is monitored by some "external" process.

               

              But yes, in theory (and in practice) that works, no discussion.

               

              Regards,

              Nico

              • 4. Re: PowerShell script to start a workflow, if the workflow is not running.
                Kumar Jaganathan Active Member

                @Sai,

                 

                Find my example and it should work for sure. I have tested too.

                 

                C:

                CD C:\Informatica\10.2.0\server\bin

                .\PmCmd.exe startworkflow -sv <Integration service> -d <DomainName> -u <User Name> -p <Password> -f <Folder Name> -nowait/wait <workflow name>

                 

                Nowait --> This will start the workflow and come to a normal position.

                wait --> This will wait until workflow completes.

                $? --> can be used to get last command status.

                • 5. Re: PowerShell script to start a workflow, if the workflow is not running.
                  Sai Ram Seasoned Veteran

                  Hi All,

                   

                  I've developed a batch script which will check the status of the workflow and if it is succeeded/aborted/stopped/failed, the script will trigger pmcmd command and make the workflow running again.

                  here is the script:

                   

                  **************************************************************************************

                  PowerShell Script:

                   

                  function Get-Data {

                      $foreach.MoveNext() | Out-Null

                      $null, $returnValue = $foreach.Current.Split(":")

                      $returnValue

                  }

                   

                  do

                  {

                  .\pmcmd getworkflowdetails -sv service_name -d domain_name -uv user_env_var_name -pv passwd_env_var -usd native -f "infa_TEST" wf_XXX_test >C:\results\file\path\results_getworkflow_details.txt

                   

                  foreach($line in (Get-Content "C:\results\file\path\results_getworkflow_details.txt")) {

                  if($line -match "Workflow run status") {

                          $null, $Name = $line.Split(":")

                          $ID    = Get-Data

                          $Status = Get-Data

                  $Name = $Name.Trim()

                          Write-Output "Current Workflow Status::"$Name

                   

                  if(($Name -match "[Stopped]") -or ($Name -match "[Aborted]") -or ($Name -match "[Succeeded]") -or ($Name -match "[Failed]") -or ($Name -match "[Terminated unexpectedly]"))

                  {

                  .\pmcmd startworkflow -sv service_name -d domain_name -uv user_env_var_name -pv passwd_env_var -usd native -f "infa_TEST" wf_XXX_test

                  }

                   

                           Write-Output "Sleeping for 600 seconds..."

                  Start-Sleep -s 600

                   

                  #       }

                      }

                  }

                  }until($infinity)

                  **************************************************************************************

                  Schedule this script to run every reg.interval of time; and also to start this script soon after the server is up.

                  -----------

                  but I've other problems.which Im going to put it in another discussion topic.

                   

                  Regards,

                  SaiRam.