I am using the function below to execute a stored proc that return an output parmtrer.
function ProcessLogRun-Start
{
[CmdletBinding()]
param(
[Parameter()]
[string]$PackageName,
[string]$MachineName,
[string]$UserName
)
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText ="dbo.ProcessLogRunStart"
$SqlCmd.CommandType=[System.Data.CommandType]'StoredProcedure'
$p1= new-object System.Data.SqlClient.SqlParameter;
$p1.ParameterName="@MachineName"
$p1.DbType = [System.Data.DbType]'String';
$p1.Size = 100
$p1.Direction = [System.Data.ParameterDirection]'Input'
$p1.Value=$MachineName
$SqlCmd.Parameters.Add($p1)>> $null;
$p2= new-object System.Data.SqlClient.SqlParameter;
$p2.ParameterName="@UserName"
$p2.DbType = [System.Data.DbType]'String';
$p2.Size = 50
$p2.Direction = [System.Data.ParameterDirection]'Input'
$p2.Value=$UserName
$SqlCmd.Parameters.Add($p2)>> $null;
$p3= new-object System.Data.SqlClient.SqlParameter;
$p3.ParameterName="@PackageName"
$p3.DbType = [System.Data.DbType]'String';
$p3.Size = 50
$p3.Direction = [System.Data.ParameterDirection]'Input'
$p3.Value=$PackageName
$SqlCmd.Parameters.Add($p3)>> $null;
$p4= new-object System.Data.SqlClient.SqlParameter;
$p4.ParameterName="@RunID"
$p4.DbType = [System.Data.DbType]'Int32';
$p4.Direction = [System.Data.ParameterDirection]'Output'
$SqlCmd.Parameters.Add($p4)>> $null;
$SqlConnection.Open();
$SqlCmd.Connection=$SqlConnection;
$SqlCmd.ExecuteNonQuery();
$lrunId = $SqlCmd.Parameters["@RunID"].Value;
$SqlConnection.Close();
$SqlCmd.Dispose()
$SqlConnection.Dispose()
return $lrunId
}
Function call
$runid=ProcessLogRun-Start -PackageName $PackageName -MachineName $env:COMPUTERNAME -UserName $env:USERNAME
The function is supposed to return a single value. However, $runid gets value as
IsPublic IsSerial Name BaseType
True True Object[] System.Array
The output of $runid
-1
6253
Why is it changing to an object array?