In any physical Windows machine after enabling Hyper-V role, one can create multiple numbers of VMs as the Virtualization technology allows us to make use of the hypervisor to manage VMs. After creating VMs in Hyper-V, connection and working can be performed through the following two ways:
- Hyper-V Remote management through Remote desktop or PowerShell
- Hyper-V Virtual Machine Connect
Both these tools help the users to connect to a Virtual Machine that has been created under hypervisor that extracts OS from the underlying host. But both have certain drawbacks when network instability is considered as a factor. Let us take a scenario where a user has a VM and has connected to it through VMConnect. By mistake, the user has turned on the firewall of that particular machine. At this point, the VMConnect connection to the VM is dropped and there is no other way to connect to that specific machine.
Similarly, in another scenario, a new VM is created and OS is installed in it. Initially, the VM is not in the domain of the Hyper-V host and trying to connect it using either the VMConnect or Remote Desktop connection is of no use.
So, from the above two mentioned cases, it can be concluded that only if the VMs are on the same domain as that of the host, disabled firewall and having a proper network access can be connected with the tools provided by Hyper-V.
PowerShell direct:
Before getting into PowerShell Direct, let us understand what PowerShell is all about. PowerShell scripts are somewhat similar to the command prompts that every OS possesses to perform certain operations or rather perform a task that could be done with GUI.
PowerShell direct is a new feature that is added in the Windows Server 2016 that allows one to connect to the VMs even if there is no network access between the host and the VM. Both the host and VM can be of different domain and even if the firewall is enabled in the VM, one can get access to it.
Command Prompt Vs PowerShell:
Command Prompts have been in use from the early stages. PowerShell advented from Windows 2004 is much more complex and powerful than its predecessor. Since Command prompts are no way match to the shells of Unix system, PowerShell came into the picture. Windows is the only operating system where GUI has got more prominence than the shells. But with the emergence of the PowerShell, it is expected that the scene could change in the near future.
The difference between Command prompts and PowerShell lies in the commands that are used to get an operation done. PowerShell scripts are made of cmdlets, which are nothing but tiny commands that can run a service.
The advantages of PowerShell over Command prompt is that administrators and power users utilize PowerShell scripts as it can perform all complicated tasks. One crucial feature of PowerShell is that it employs pipes as Linux does and more than data manipulation, the objects are manipulated through pipes in cmdlets. The objects are usually from a .NET framework that is created using C#. This one extended feature makes PowerShell stand far ahead from command prompts.
How PowerShell Direct connects with VM?
Traditional methods of PowerShell to be connected with the VMs in Hyper-V requires PSRemoting to be enabled and VM must be in boot up state. PowerShell Direct utilizes VMBus of the Hyper-V architecture to connect the host with the VMs even when there is no network connectivity between the two. VMBus is an internal communication channel that connects and transfers data/files between the host and VMs. VMBus fetches two important aspects of the VM to be connected with the host.
- VM name
- VM GUID
VSP(Virtualization Service Provider) resides on the host side whereas VSC(Virtualization Service Consumers) will be present in the VMs. The transfer of files between these two starts by creating an SMB Share. For the effective transferring of files, Hyper-V session service and guest services that are installed as a part of installation services are mandatory.
Benefits of PowerShell direct over any other tool:
The following are the benefits of PowerShell direct over any other tools that are used to connect with the VMs.
1. Network configuration:
With the use of PowerShell Direct, one could easily connect to the VMs within a host no matter what the particular VM’s network configurations may be. As already stated, the host and VM can be of a different domain, the network wasn’t configured or even if a firewall is enabled, PowerShell Direct allows to access and perform operations on the VM. It allows you to enable Active Directory services.
2. Human errors:
PowerShell Direct is so helpful in a way that if a user logs in to VM through either VMConnect or Remote Connection by PowerShell and by mistake configures something that locks the user within the VM. No other user could use the VM anymore. During these situations, PowerShell Direct makes it easier to connect with the VM and change the configuration such that the VM could be connected by other users as well.
3. Status check:
PowerShell direct can be used to execute simple queries to check the status of VMs within a host. Whether the VM is booted up, network connectivity check etc can be performed.
Limitations:
Though PowerShell Direct has numerous advantages, it also has its share of limitations which are listed below.
- PowerShell Direct, as of now is supported only for Windows 10 and Windows 2016( scenario might change in future)
- The Host and Guest VM OSes must be either Windows 10 or Windows 2016
- The VMs under a particular host can be accessed by PowerShell Direct. No cross-host access is allowed
- The user must be logged on to the host with Administrator Privileges
- To connect with a VM under a host, its credentials must be known
- The VM must be virtually running and must be booted
To know more about managing Hyper-V VMs using PowerShell Direct, check out here.
Got questions? Email us at: vembu-support@vembu.com for answers.
Follow our Twitter and Facebook feeds for new releases, updates, insightful posts and more.