You could try the STart-Transcript and Stop-Transcript cmdlets, or revert to some Write-Output lines at strategic places in the script.
And split the lines in smaller parts, so you can see the intermediate results (in other words what you place in the pipeline).
For example, first do the Get-Datastore and store the result in a variable.
Then use that variable as input to the Get-Stat cmdlet.
Now you can display the contents of that variable with a Write-Output cmdlet.