First thing you'll have to do, before calling the Get-Stat2 function, is to make the function known to PowerShell.
There are a couple of methods to achieve this.
One of these is to copy the function into a .ps1 file, and then add your call at the end of this .ps1 file.
Then you call the .ps1 file from the PowerCLI prompt.
Attached a sample .ps1 file that gets the statistics for the full previous day