Hi,
Yes I meant when logged onto the server via RDP and running powershell.exe
Some very interesting facts.
Running the example you gave above, I can now see the log file, I can see the print statements within the workflow but the script still never ends when executing from the batch server. Its printing output to the log file and no error and it still hangs there for hours for a script that ought to run for seconds. I do not see any errors but it is still running.
Another fact is this, whenever I call a function inside the workflow it hangs just before it gets to the function as I cannot see any print statements after the function.
Lastly, any inline script block also makes the script hang.
As expected, whenever it hangs it is not possible to delete the log file as the PowerShell process is still locking it, however once the process is killed then it is possible to delete the file.
When I remove the following, then the workflow works.
- Removal of the function which tests connectivity to SQL instances.
- Removal of the inline script block.
Once more, when executed from the server directly, no such issues.
The SQL check function can be seen below.
Function CheckSQLInstance{
param
(
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
$sql_server,
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=1)]
$db_name
)
try
{
#Return extra useful info by using custom objects
$ping_status = "" | Select-Object -Property log_date, stage, status, error_message
$ping_status.log_date = (Get-Date)
$ping_status.stage = 'Ping SQL instance for $sql_server'
#test connection for a sql instance
$connectionstring = "Data Source=$sql_server;Integrated Security =true;Initial Catalog=$db_name;Connect Timeout=5;"
$sqllconnection = New-Object System.Data.SqlClient.SqlConnection $connectionstring
$sqllconnection.Open();
$ping_status.status = $true
$ping_status.error_message = ''
return $ping_status
}
Catch
{
$ping_status.status = $false
$ping_status.error_message = $_.Exception.Message
return $ping_status
}
finally{
$sqllconnection.Close();
}
}