Pssession- computername vs vmname for Enter-pssession
-
Ok, I get the difference between the vm name vs computer name. The computer name is what I'm referring too. The one in system preferences. Not the one in hyper-v mgr. In my case I just made them the same.
If the running vm with the computer named the same as the vmname can see dns shouldn't either cmdlet work? Do they need to be named separately in order to use either cmdlet?
-
Either will work, but the requirements aren't the same.
When you use Enter-PSSession -VMName, you are actually using PowerShell Direct.
PowerShell Direct allows Windows PowerShell management inside a virtual machine regardless of the network configuration or remote management settings on either the Hyper-V host or the virtual machine. This makes it easier for Hyper-V Administrators to automate and script virtual machine management and configuration.
This makes managing VMs using PowerShell a lot easier. If you can log on to the Hyper-V host, you can use PowerShell commands to manage the VMs on that host, even if the VM is not on the same network, is not part of the same domain, is not in your trusted hosts list. Without any additional configuration, you can manage the VMs running in Hyper-V, as long as you are a Hyper-V admin and have valid credentials on the VM.
When you use Enter-PSSession -ComputerName, you need to meet certain requirements and have everything configured to support remote PSSessions. This is why it works when you use -VMName from the Hyper-V host and fails when you try to use -ComputerName.
In order to use -ComputerName, the Hyper-V host needs to be configured properly:
Has remote management been configured on the VM? (Enable-PSRemoting)
It must be able to resolve the DNS name (NOT the VMName). Can you ping the VM by name from the Hyper-V host?
There must be network connectivity.
- Is the VM connected to a network?
- Have a valid IP address?
- Is the Hyper-V host also connected to this network (directly or routed)?
- Is the network the VM is connected to is a private? The Hyper-V host cannot connect to this network.
Is the VM in the same domain as the Hyper-V host? If not, is the VM listed in the TrustedHosts list?
So there is a lot of configuration that has to happen before you can remotely administer a VM. This is where PowerShell Direct comes to the rescue. There are much fewer requirements to allow PowerShell Direct.
Configuration requirements for PowerShell Direct:
- The virtual machine must be running locally on the host.
- The virtual machine must be turned on and running with at least one configured user profile.
- You must be logged into the host computer as a Hyper-V administrator.
- You must supply valid user credentials for the virtual machine.
Make note of that first bullet. PowerShell Direct (-VMName) is only available from the Hyper-V host.
https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/powershell-direct
https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/manage/manage-windows-virtual-machines-with-powershell-direct -
The reason -VMName works for you is because it doesn't need any additional configuration.
If you configure it properly -ComputerName will work as well.
-
@Mike-Rodrick @Mike-Rodrick A million thank you's for all of your assistance and expertise. I thought I had configured everything for computername access, but I'll go through the set up again. Powershell for me is squeezing square peg into a round hole. Do you know where in the menu I can find the solved option?
-
You're welcome, glad I could help!
Let me know if have more questions later, it can be tricky when dealing with a workgroup environment.