Hello, mazdajai-
For the first part, one way that you could pass the script string to the myScript.ps1 as a parameter would be to have the script text itself as a variable. For example:
## store the script text for Invoke-VMScript in a variable
$strScriptTxt = 'uname -a'
## call the PowerShell script with the two parameters
myScript.ps1 myVMName $strScriptTxt
As for how to only try to run something on VMs that have Tools running, you could do something like:
Get-VM | ?{$_.ExtensionData.Guest.ToolsRunningStatus -eq "guestToolsRunning"} | %{
## do stuff here
Invoke-VMScript -VM $_ -GuestCredential ... ## and so on
} ## end foreach-object
How does that do?