Can you attach that MyScript.ps1 ?
Do you call the Get-VMUptime function at the end of the .ps1 file ?
The file content should look something like this
function Get-VMUptime {
....
}
$vm = Get-VM -Name MyVM
$start = (Get-Date).AddDays(-30)
Get-VMUptime -VM $vm -Start $start
Have a look at the samples at the end of my post.