我对自动化是全新的,对 Powershell 也很陌生,所以我希望这是一个简单的修复。 :)
我正在尝试让一些代码运行。据我所知,它确实运行了,但测试窗格没有显示任何内容。基于此线程:Azure powershell Runbook 不显示任何输出 https://stackoverflow.com/questions/54965153/azure-powershell-runbook-dont-show-any-output,我确实尝试重新发布代码并清除浏览器缓存,但这对我的情况没有帮助,所以我认为代码有问题?
这是我的(通用)代码):
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:
...这对于了解它是否真正运行并没有多大帮助。
预先感谢您提供的任何帮助! :)
[编辑]代码肯定没有运行。存储过程将一个条目插入到历史表中,并且没有它运行的记录,无论是测试还是运行发布的输出。
不过,有趣的是,当我运行已发布的输出时,没有错误也没有警告,但它确实在“输出”选项卡中显示“此作业没有任何输出”。
[编辑#2]:它也没有在我的本地计算机上写入任何内容?
[编辑 #3]:将 inlinescript 块内的 Write-Output 替换为 Write-Host。无论是在 Azure 管理控制台上还是在我的本地计算机上,都没有任何变化。
我的猜测是你创建了一个电源外壳运行手册,而不是PowerShell 工作流程运行手册。如果这是正确的,那么您的 Runbook 代码declares一个名为 DB_DailyTasks 的工作流程,但从未invokes它。例如,您可以declare一个函数,但不希望它自动invoked因为这个。
除非你确定你需要一个workflow,不是常规的 PowersShell Runbook,我建议删除workflow
and InlineScript
从您的代码中,并处理常规的 PowerShell。
但是,如果您确实需要它成为一个工作流程(不推荐,除非您必须使用检查点之类的东西)parallel
and foreach -parallel
),然后创建一个“PowerShell Workflow”类型的 Runbook:它处理workflow
关键字不同,因此您的代码是正确的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)