gpt4 book ai didi

来自另一个 RunBook 的 Azure 自动化 RunBook

转载 作者:行者123 更新时间:2023-12-03 01:40:45 28 4
gpt4 key购买 nike

我有一个运行手册名称“RB_ConnectSQL”

workflow RB_ConnectSQL
{
[OutputType([string])]
param
(
[Parameter(Mandatory=$true)] [string] $SqlServer,
[Parameter(Mandatory=$false)] [int] $SqlServerPort = 1433,
[Parameter(Mandatory=$true)] [string] $Database,
[Parameter(Mandatory=$true)] [string] $Procedure,
[Parameter(Mandatory=$true)] [string] $SqlCredentialName
)
$SqlCredential = Get-AutomationPSCredential -Name $SqlCredentialName
$SqlUsername = $SqlCredential.UserName
$SqlPass = $SqlCredential.GetNetworkCredential().Password

inlinescript
{
$haveError = 0
$DatabaseConnection = New-Object System.Data.SqlClient.SqlConnection("Server=tcp:$using:SqlServer,$using:SqlServerPort; Database=$using:Database; User ID=$using:SqlUsername;Password=$using:SqlPass; Trusted_Connection=False; Encrypt=True; Connect Timeout=7200;")

$outputDataTable = New-Object System.Data.DataTable
[string[]] $ColumnNames
try
{
$DatabaseConnection.Open()
$Cmd=new-object system.Data.SqlClient.SqlCommand
$Cmd.Connection = $DatabaseConnection
$Cmd.CommandText = 'EXEC ' + $using:Procedure + ';'
$Cmd.CommandTimeout = 7200
$sqlDataAdapter = New-Object System.Data.SqlClient.SqlDataAdapter $Cmd
$dataSet = New-Object System.Data.DataSet
Write-Output($Cmd.CommandText)
$sqlDataAdapter.Fill($dataSet) | out-null
if ($dataSet.Tables[0].Rows.Count -gt 0)
{
$outputDataTable = $dataSet.Tables[0]
}
else
{
$outputDataTable = "SQL Stroc Proc Executed”
}
}
catch
{
#write your own error handling code here.
#if required send error message in email.
}
finally
{
if ($Cmd -ne $null)
{
$Cmd.Dispose
}

$DatabaseConnection.Close()
$DatabaseConnection.Dispose()
}
}
}

另一个运行手册名称“RB_Daily_Transaction_Summary_Record”

workflow RB_Daily_Transaction_Summary_Record
{
$dataTable = RB_ConnectSQL -SqlServer 'blahblah.database.windows.net' -Database 'blahDev' -Procedure 'sp_Daily_Transaction_Summary_Record' -SqlCredentialName 'blahCredential'
Write-Output($dataTable)
}

Runbook“RB_Daily_Transaction_Summary_Record”假设调用“RB_ConnectSQL”并传入所需参数,以便在 Azure SQL Server 中执行存储过程。但是我收到错误

At line:78 char:17 + -SqlServer 'blahblah.database.windows.net' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Cannot find the '-SqlServer' command. If this command is defined as a workflow, ensure it is defined before the workflow that calls it. If it is a command intended to run directly within Windows PowerShell (or is not available on this system), place it in an InlineScript: 'InlineScript { -SqlServer }'

我可以知道我在操作手册上犯了任何错误吗?

最佳答案

当您想将一个命令分成多行时,请在每行末尾添加空格和反引号(最后一行除外)。

在您的情况下,它应该使用以下格式工作:

workflow RB_Daily_Transaction_Summary_Record
{
$dataTable = RB_ConnectSQL
-SqlServer 'blahblah.database.windows.net' `
-Database 'blahDev' `
-Procedure 'sp_Daily_Transaction_Summary_Record' `
-SqlCredentialName 'blahCredential'
Write-Output($dataTable)
}

关于来自另一个 RunBook 的 Azure 自动化 RunBook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53801426/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com