Automic Community

Expand all | Collapse all

Powershell 5.1 script issue while running automic workflow

  • 1.  Powershell 5.1 script issue while running automic workflow

    Posted 09-12-2019 11:25 AM
    ​Dear,

    when I am executing the below code,I see the error like " Exception found: System.Management.Automation.RuntimeException
    Exception text: You cannot call a method on a null-valued expression."


    $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField"

    $objectRef = $host.GetType().GetField("externalHostRef", $bindingFlags).GetValue($host)


    $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetProperty"

    $consoleHost = $objectRef.GetType().GetProperty("Value", $bindingFlags).GetValue($objectRef, @())

    [void] $consoleHost.GetType().GetProperty("IsStandardOutputRedirected", $bindingFlags).GetValue($consoleHost, @())

    $bindingFlags = [Reflection.BindingFlags] "Instance,NonPublic,GetField"
    $field = $consoleHost.GetType().GetField("standardOutputWriter", $bindingFlags)

    $field.SetValue($consoleHost, [Console]::Out)

    $field2 = $consoleHost.GetType().GetField("standardErrorWriter", $bindingFlags)

    $field2.SetValue($consoleHost, [Console]::Out)

    Please help me in resolving this issue.

    Regards
    Praveen CH


  • 2.  RE: Powershell 5.1 script issue while running automic workflow

    Posted 09-13-2019 02:17 AM
    This is not an Automic but Powershell issue. What are you trying to achive with this code?

    ------------------------------
    Swisscom & WorkflowCommander
    ------------------------------