Invoke-Command on remote isolated VM

I’ve got this remote Hyper-V machine that I’m using as a lab server. Within this lab there are serveral virtual machines that run in an isolated lan and can only reach the outside world over a proxy, so connecting to them from the “production” network isn’t possible. What I’m trying to do is remote into the Hyper-V host, and execture commands on the isolated VM’s. I’ve figured out how to do that but’s its a bit much if you ask me. I was wondering if there’s an easier/smarter way to do it?


$session = New-PSSession -ComputerName whv -Credential (Get-StoredCredential -Target "HyperVManager/WHV") -Authentication Credssp
$vmsession = Get-Credential -UserName "Administrator" -Message "Enter Credentials"
$Bits = "Bits"

Invoke-Command -Session $session -ArgumentList $vmsession, $Bits {Invoke-Command -VMName "Edge01" -Credential $args[0] -ArgumentList $args[1] {Get-service -Name $args[0]}}

That’s pretty much how it’s done.

Thanks Don!

Hi Micheal waterman,

I need help on VMware.

I’m using vcenter on vcenter I’ve created two hosts where each host is having two windows vms.

“Help create a script to find vms in a vcenter where vmtools not installed and install them without rebooting them”

a) finding “windows” vms in a vcenter where vmtools are not installed
b) install vmtools on them without rebooting the vm after installing it.

Both should be in the same script.

The script for the above line or Help me how to connect remotely to vm using Invoke-Command.It would mean a lot if you help me out

Hi Varna,

You need the VMware powercli modules for that as you cannot use invoke-command to a remote esxi machine. Just use the get-vm to get all the machines and find a property that indicates the existence of the VMware tools. I’m pretty sure there’s a way to remotely install the VMware tools next via the VMware interface itself.

Have fun!