Action linked to Timer object not getting executed(Powershell 3)

Welcome Forums General PowerShell Q&A Action linked to Timer object not getting executed(Powershell 3)

Viewing 3 reply threads
  • Author
    Posts
    • #249224
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member
      In the script below an Action(update and print count every timer update) is linked to Timer object , but the Action is not getting executed.

      What’s missing?

      Console Output-  

      Script- [/crayon] [/crayon]
    • #249281
      Senior Moderator
      Topics: 9
      Replies: 1309
      Points: 4,781
      Helping Hand
      Rank: Community Hero

      $n is out side the action context so inside the the if condition it will always be $null. How are you making sure actions is not executed ? You can try creating temp files in both if and else condition and see which part is executing.

      • This reply was modified 1 month, 1 week ago by kvprasoon. Reason: post correction
    • #249347
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Write-Output in if-else action  blocks ensures if the action is getting executed.

      Also , tried setting $n to global and script scopes but there is still no output.

    • #249575
      Participant
      Topics: 1
      Replies: 2
      Points: 17
      Rank: Member

      Replaced Write-Output in the Action Block with Write-Host and the issue was resolved.

      Write-Output pipes the output down a cmdlet and doesn’t write to the Console .

      Inorder to write to the Console, Write-Host has to be used.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.