Streaming Output to Console

Just for fun, I thought it’d be cool to track the price of bitcoin using powershell (my boss is still into it). I found an API that returns everything I want using JSON format - and that works perfectly fine – have a look below if you’d like to replicate. My problem is, if I want to make it a “live ticker” - so to speak - I’m expecting to do something like Do {Get-BitcoinValue; Start-Sleep -Sec 60 } while ($true) however, the first Get-BitcoinValue doesn’t display anything… then after 60 seconds, I get the first and second results at the same time, then every 60 seconds a new “row” is added. I feel like this is something to do with how powershell handles streaming output to the host, but I have no idea how to workaround that. Curious if anyone has any thoughts.

$ApiURL = ''
# you can leave out the below line if you don't want the headache of making a default view
#Update-FormatData "$($PSScriptRoot)\BitcoinObjectView.format.ps1xml"

function Get-BitCoinValue {
    $data = Invoke-RestMethod -Uri $ApiUrl
    $Time = ([datetime]$data.time.updatedISO).ToLocalTime()
    $obj = New-Object -TypeName psobject -Property ([ordered]@{
        DateTime = "$("{0:yyyy-MM-dd HH:mm:ss}" -f $Time.tolocaltime())"
        Coin = $Data.ChartName
        USD = ("{0:c}" -f [double]$data.bpi.usd.rate.replace(',',''))
        EUR = ("$([char]0x20ac)" + ("{0:n2}" -f [double]$data.bpi.EUR.rate.replace(',','')))
        GBP = ("$([char]0x00A3)" + ("{0:n2}" -f [double]$data.bpi.GBP.rate.replace(',','')))

And if you’re curious about the default view:

<?xml version="1.0" encoding="utf-8" ?>


Just realized, I could probably just make a Timer object, and attach Get-BitCoinValue to the “elapsed” event… I should give that a shot…