Welcome Forums General PowerShell Q&A How to generate the custom event from script.

Viewing 2 reply threads
  • Author
    Posts
    • #167461
      Participant
      Topics: 9
      Replies: 8
      Points: 102
      Rank: Participant

      Hi, there!

      I have read the documentation about PowerShell events cmndlets (New-Event, New-ObjectEvent, Register-EngineEvent, etc.), but there no clear information about this kind of task: for example I need to raise the event (to write “It’s reached”), when some code is reach some value:

      for($i=0; $i -gt 10; $i++) {

      if($i -eq 5) { #HERE THE CODE FOR GENERATE EVENT – ?????? }

      }

      I couldn’t find the similar code example through the Google, so may somebody to provide the code example for generate of this type event ?

       

    • #167566
      Moderator
      Topics: 3
      Replies: 113
      Points: 585
      Helping Hand
      Rank: Major Contributor

      Ah, speaking of clear information, perhaps you could give a bit more detail on what you want to do.

      If you just want the script to write “It’s reached” to the screen when a condition is met, it’s as simple as this:

      if ($i -eq 5) {echo "It's reached"}

      and in fact you don’t even need ‘echo’, so it can just be:

      if ($i -eq 5) {"It's reached"}

      Why do you need an event, what is the event supposed to trigger, and what is handling the event when it occurs?

      Also, please format your code with pre tags or by using a github gist, as per this post.

    • #167788
      Participant
      Topics: 9
      Replies: 8
      Points: 102
      Rank: Participant

      Hello!

      You’re right.

      Perhaps it’s not clear task and I don’t need to use events here – sorry. I’ll try to think better on this task.

      Thanks.

Viewing 2 reply threads
  • The topic ‘How to generate the custom event from script.’ is closed to new replies.