Write-information not working in a worflow

Welcome Forums General PowerShell Q&A Write-information not working in a worflow

Viewing 5 reply threads
  • Author
    Posts
    • #178233
      Participant
      Topics: 1
      Replies: 4
      Points: 28
      Rank: Member

      Having an issue using write-information in a workflow. Hoping i'm doing something silly and someone can point it out!

      Its a simple script!

      When i set the $InformationPreference in the shell i'm using it will work, but this is a workflow and will run on many random systems. I have tried to set it at the start of the workflow, but it doesn't see to work. So i commented it out.

      Hoping this is not a bug as write-information is supported in a workflow! Cant get any simpler than below!

       

      workflow test-workflow
      {
      #$InformationPreference = "Continue"
      Write-Information -MessageData "Started Workflow" -InformationAction Continue

      }

    • #178245
      Moderator
      Topics: 0
      Replies: 42
      Points: 399
      Team MemberHelping Hand
      Rank: Contributor

      By "work", do you mean output to the host/log?

      By default, Write-Information does not output to host, as (as you've noticed) InformationPreference is set to SilentlyContinue. It also doesn't support adding the "PSHOST" tag (unless you use $PSCmdlet.WriteInformation("Message", "PSHOST"), though I guess that's no longer Write-Information).

      You can, however, capture it in -InformationVariable and various other methods (Jaykul's Information module is neat).

      Having said that, in PowerShell >5.0 Write-Host is essentially Write-Information with the magic PSHOST tag applied (some handwaving included, here).

    • #178248
      Participant
      Topics: 1
      Replies: 4
      Points: 28
      Rank: Member

      Some additional context. This is run in SMA. This will run as part of a parent / child workflow with information being passed between them. Using write-output pollutes the information being passed between the workflows. Using write-host displays nothing either.

      I can put a sample parent / child workflow together if that would help demonstrate the issue better?

    • #178257
      Participant
      Topics: 1
      Replies: 4
      Points: 28
      Rank: Member

      Here is a sample with write-output / write-information and write-verbose. You can comment whatever it is you want to test against.

      Essentially i want test-parent to receive the $value from test-child, and only that value. I want the write-output displayed, but not inside the $value.

      I can use write-information, but $InformationPreference = "Continue" must be set for that shell to work I cant seem to set it globally or for all users / shells spawned.

       

      Parent workflow:

      workflow test-parent {

      write-information -MessageData "Starting Parent!" -InformationAction Continue
      #Write-Verbose "Starting Parent! $(date)" -Verbose

      $result = test-child
      write-information "Result: $result" -InformationAction Continue
      #Write-Verbose "Result: $result" -Verbose
      write-output "$result"

      write-information "Finished Parent!" -InformationAction Continue
      #Write-Verbose "Finished Parent! $(date)" -Verbose
      }

      Child workflow:

      workflow test-child
      {

      Write-Information -MessageData "Starting Child!" -InformationAction Continue
      Write-Output "Starting Child!"
      #Write-Verbose "Starting Child! $(date)" -Verbose

      $value = "ID = 21"
      Write-Information -MessageData $value -InformationAction Continue
      #Write-Verbose "$value" -Verbose
      Write-Output "$value"

      Write-Information -MessageData "Finished Child!" -InformationAction Continue
      #Write-Verbose "Finshed Child! $(date)" -Verbose
      Write-Output "Finished Child!"
      return $value

      }

       

      Maybe there's a better way to run this altogether! Just looking for thoughts / tips!

    • #178263
      Moderator
      Topics: 0
      Replies: 42
      Points: 399
      Team MemberHelping Hand
      Rank: Contributor

      My apologies – I managed to miss the word workflow above.

      Personally speaking, I'd use output to transmit the data and information / verbose to narrate actions (as it were), though that doesn't translate to workflow very well. Is the purpose logging, along with the transmission?

    • #178311
      Participant
      Topics: 1
      Replies: 4
      Points: 28
      Rank: Member

      Hi James, i appreciate your replies!

      I don't know what you mean when you say "Is the purpose logging, along with the transmission".

      Verbose looks like it will give me the displayed output along with the values.

       

      Not sure why the simple example which is supposed to overwrite the $InformationPreference doesn't work.

      workflow test-info
      {
      Write-Information -MessageData "Started Workflow" -InformationAction Continue

      }

Viewing 5 reply threads
  • The topic ‘Write-information not working in a worflow’ is closed to new replies.