I would like a try...catch block around the cmdlet to gather information for debugging purposes that grabs ANY kind of results from the call, but all the research i've done on the cmdlet have failed to find ANY kind of exceptions being thrown.
Need some assistance with powershell.
the GET-ClusterNode cmdlet is failing 'sometimes'
I would like a try...catch block around the cmdlet to gather information for debugging purposes that grabs ANY kind of results from the call, but all the research i've done on the cmdlet have failed to find ANY kind of exceptions being thrown.
I've tried several variations of try...catch but i am failing at the task due to me not being able to see if there is an error being thrown.
The script loads an array with the results of the cmdlet into an array, then check for a zero value of records, i can fire the cmdlet again, but that isn't an answer - just a hack work around that might work or not.
As i mentioned, the cmdlet is failing RANDOMLY, and on several different systems, using the exact same script.
The script execution depends on the results of this command to continue processing.
Suggestions would be greatly appreciated.
Write-Output "$(Get-Date): Display ""Get-ClusterNode"" output before trying to capture it to an array object (for debugging purposes)"
Get-ClusterNode
if (!$?) {Write-Output "$(Get-Date): The ""Get-ClusterNode"" command failed"}
# Wait a few seconds before this script attempts to capture Get-ClusterNode into an object
Start-Sleep -Seconds 3
Write-Output ""
Write-Output "$(Get-Date): Capture ""Get-ClusterNode"" output to an array object (`$ClusterNodeCollection_OBJ) for further processing"
Write-Output ""
$PotentialFailureReason_DSC = "Error while executing ""Get-ClusterNode"""
[array]$ClusterNodeCollection_OBJ = Get-ClusterNode
if (!$?) {$ErrorMessage_STR = $error[0].ToString(); $ErrorPosition_STR = $error[0].InvocationInfo.PositionMessage.ToString(); job_failure $ErrorMessage_STR $ErrorPosition_STR}
Write-Output "`$ClusterNodeCollection_OBJ ="
Write-Output ""
$ClusterNodeCollection_OBJ
$ClusterNode_CNT = $ClusterNodeCollection_OBJ.Count
Write-Output ""
Write-Output "`$ClusterNode_CNT = $ClusterNode_CNT"