Runbook test pane is not showing Write-Output

邮差的信 提交于 2019-12-11 16:22:38

问题


I'm brand new to automation, and pretty new to Powershell as well, so I'm hoping this is a simple fix. :)

I'm trying to get some code to run. And for all I know, it does run, but the test pane doesn't show anything. Based on this thread: Azure powershell runbook don't show any output, I did try republishing the code and clearing my browser cache, but that didn't help in my case, so I'm thinking there's an issue with the code?

Here's my (genericized) code):

workflow DB_DailyTasks 
{
    Write-Output "Code starting"

    inlinescript 
    {
        [string] $SqlServerName = "myDb.database.windows.net"
        $Credential = Get-AutomationPSCredential -Name "myDatabase-automation"
        # Setup credentials   
        $ServerName = $Using:SqlServerName
        $UserId = $Using:Credential.UserName
        $Password = ($Using:Credential).GetNetworkCredential().Password

        # Execute the udp_myProc procedure

        # Create connection for each individual database
        $DatabaseConnection = New-Object System.Data.SqlClient.SqlConnection
        $DatabaseCommand = New-Object System.Data.SqlClient.SqlCommand

        Write-Output "ConnectionState is: $(DatabaseConnection.State)"

        $DbName = "myDb"

        # Setup connection string for $DbName
        $DatabaseConnection.ConnectionString = "Server=$ServerName; Database=$DbName; User ID=$UserId; Password=$Password;"
        $DatabaseConnection.Open();

        Write-Output "ConnectionState is: $(DatabaseConnection.State)"

        # Create command for a specific database $DBName
        $DatabaseCommand.Connection = $DatabaseConnection

        Write-Output "Running udp_myProc procedure"

        $DatabaseCommand.CommandText = "EXECUTE [dbo].[udp_myProc]"
        $NonQueryResult = $DatabaseCommand.ExecuteNonQuery()

        # Close connection to $DbName
        $DatabaseConnection.Close()        
    }
}

...and here's what I see in the test pane when I try to test:

...which isn't terribly helpful in knowing whether it actually ran.

Thanks in advance for any help you can provide! :)

[Edit] The code is definitely not running. The stored procedure inserts an entry into a history table, and there's no record of it running either for the tests or for when I ran the published output.

Interesting note, though - when I ran the published output, there were no errors and no warnings, but it did say, "This job does not have any output" in the Output tab.

[Edit #2]: It doesn't write anything on my local computer either??

[Edit #3]: Replaced Write-Output with Write-Host inside the inlinescript block. No change, either on Azure admin console or on my local computer.


回答1:


My guess is that you created a PowerShell runbook, not a PowerShell Workflow runbook. If this is correct, then your runbook code declares a workflow called DB_DailyTasks, but never invokes it. For example, you could declare a function, but would not expect it to be automatically invoked because of that.

Unless you are certain that you need a workflow, not a regular PowersShell runbook, I would recommend removing workflow and InlineScript from your code, and deal with regular PowerShell.

However, if you really need it to be a workflow (not recommended unless you have to use checkpoints and things like parallel and foreach -parallel), then create a runbook of the "PowerShell Workflow" type: it treats the workflow keyword differently, so your code would be correct.



来源:https://stackoverflow.com/questions/58032960/runbook-test-pane-is-not-showing-write-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!