Hyper-V New features are available in Windows 2016 Server OS and Windows 10 OS and it’s called the Windows PowerShell Direct. Windows PowerShell Direct helps the System Administrator to run the PowerShell commands inside a Virtual Machine(VMs) from the Host Operating System easily. There is no Network connection or Firewall Configuration required from the Host Operating System to a Virtual Machine(VMs).
Windows PowerShell Direct helps the System Administrator to manage/handle Branch location Virtual Machines through VMs connected Host Machines from the Hub location.
- Administrator must be logged in the Host machine as an Hyper-V Admin
- Administrator must know the Virtual machine’s Credential details
- Host Machine must run Windows 10 or Windows 2016 Server OS
- Virtual Machines which are running on Windows 10 or Windows 2016 Server OS Host machines, the Windows PowerShell Direct commands will not be support or work in earlier Operating System
- Windows PowerShell Command will be working only on the Local Host Machine Connected to Virtual Machines only
Below are the few windows PowerShell Direct commands, how to manage the Virtual Machines through Windows PowerShell Direct.
#To login Virtual Machine and get the Virtual Machine Details.
PS C:\> Enter-PSSession -VMName “test1”
Once you enter the above command, and asking for login credentials.
[test1]: PS C:\> hostname
[test1]: PS C:\> ipconfig
After login to the Virtual Machine, above commands help to get the Hostname and IP address details. Refer the following screenshot.
#Restart the Virtual Machines.:
PS C:\> Restart-VM -VMName “test1” -AsJob
#Rename Computer Name:
Rename-Computer helps to rename the connected remote Virtual machine or local computer. One command rename one computer.
First login to the connected Virtual machine and run the below command.
[test2]: PS C:\> Rename-Computer -NewName “WIN10NODE” -LocalCredential administrator -Force -PassThru -Restart
#Enable & Disable Remote Virtual Machine Network Adapter:
When Administrator wants to Disable a particular Virtual Machine through Host machine due to some security reasons, the following commands will help.
Below command help to disable the VM, once problem resolved we can enable it.
First login to a particular VM which is disable the Netadapter First.
Once the below command runs, one popup will be displayed and if you select yes and the command will do the action.
[test2]: PS C:\> Disable-NetAdapter -Name “*”
If you know the Netadapter name you can mention the name, if you put * it will disable all the active adapters. Refer below screen shots.
Enable Netadapter.
#Assigning IP address to Virtual Machine
The Administrator has to change the IP address since users are moving from department to another department or changing the project.
For this purpose we can use the below Windows powershell Direct command to change the Virtual Machine IP address remotely.
New-NetIPAddress -InterfaceIndex 3 -IPAddress 192.168.103.187 -PrefixLength 24 -DefaultGateway 192.168.103.1
#Restart Remote Virtual Machine Services.
Windows PowerShell Direct helps the Administrator to restart the Virtual Machine Services from Host Machine itself, and also check the status of Virtual Machine service status.
First Login to Remote Virtual machine using the following command.
PS C:\> Enter-PSSession -VMName “test2”
After providing the login credential you can run the below commands to check the VMs service status, and also you can stop, start and restart the services.
This command displays all the service details from the remote VMs.
[test2]: PS C:\> Get-Service
#Stop and Start services:
Refer below command and screenshots. If you run the below command stop the services and it required you start also.
[test2]: PS C:\>stop-Service -name WSearch
[test2]: PS C:\>start-Service -name WSearch
You can filter the Virtual Machines service status separately, like stop services and running services. Refer below command and screenshots.
[test2]: PS C:\>Get-Service | Where-Object {$_.status -eq “running”}
[test2]: PS C:\>Get-Service | Where-Object {$_.status -eq “stopped”}
#Remote Virtual Machine Process Details:
You can check the Remote Virtual machine currently running process details from Host machine.
[test2]: PS C:\> Get-Process
User reporting slow response and Administrator suspect some process or particular process highly utilized and you filter that process separately and you can stop the process from the host machine itself.
Refer below screenshots.
[test2]: PS C:\> Get-Process notepad
[test2]: PS C:\> Get-Process notepad, winlogon
[test2]: PS C:\> Get-Process notepad, winlogon, system
#Stop and Start Process
Conclusion:
Windows PowerShell Direct’s easy commands help to handle the Host connected Virtual Machines. Network connections and Firewall rules are not required to maintain the Virtual Machines. So incase any issue occurs in the user Virtual Machines you can handle or maintain Virtual Machines from Host machines itself.
Note: Windows PowerShell Direct is available only in Windows 10 and Windows 2016 Server OS.
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.