This error occurs for me when I loop through a list of $CurrentServers. The solution was to add Out-Host to the end of the output line.
Operation is not valid due to the current state of the object
At line: 0 char: 0
$dsOut = Invoke-sqlcmd2 -ConnectionTimeout 10 -ServerInstance $CurrentServer -Query $SQL -Verbose -QueryTimeout 10 -Database master_admin -As DataTable # Use Out-Host to prevent format-table errors $dsOut |Select-Object * |ft -AutoSize |Out-Host