Here is a thingy.
function PingVM($hash, $vmname) {
$vmname = ParseVMName $vmname $false
if (!$vmname) { $vmname = ParseHash $hash $true }
$vm = FindVM $hash $vmname
$ipAddress = $vm.virtualMachine.network.publicIpAddresses[0].ipAddress
$credential = GetSecureVMCredentials $vmname
$sessionOptions = New-PSSessionOption -SkipCACheck -SkipCNCheck
$fancyMessage = "PowerShell says hello!"
Invoke-Command -ComputerName $ipAddress -Credential $credential -UseSSL -SessionOption $sessionOptions -ScriptBlock {
$hostname = hostname
Write-Output "Ping successful. Hostname: $hostname"
Write-Output $using:fancyMessage
}
}
I need a thingy that lets me write this instead:
function PingVM($hash, $vmname) {
$fancyMessage = "PowerShell says hello!"
RemotelyExecute $hash $vmname -ScriptBlock {
$hostname = hostname
Write-Output "Ping successful. Hostname: $hostname"
Write-Output $using:fancyMessage
}
}
What does the RemotelyExecute
function look like?