Dark Mode

5 captures
01 Dec 2016 - 02 Nov 2017
Nov DEC Jan
01
2015 2016 2017
success
fail
About this capture
COLLECTED BY
Organization: Internet Archive
The Internet Archive discovers and captures web pages through many different web crawls. At any given time several distinct crawls are running, some for months, and some every day or longer. View the web archive through the Wayback Machine.
TIMESTAMPS
The Wayback Machine - https://web.archive.org/web/20161201024553/https://technet.microsoft.com/en-us/windows-server-docs/compute/hyper-v/manage/manage-windows-virtual-machines-with-powershell-direct
Table of contents

Shared to

Table of contents +
TOC
Collapse the table of content
Expand the table of content

Manage Windows virtual machines with PowerShell Direct

Kathy Davies|Last Updated: 10/20/2016
|
3 Contributors

Applies To: Windows 10, Windows Server 2016

You can use PowerShell Direct to remotely manage a Windows 10 or Windows Server 2016 virtual machine from a Windows 10 or Windows Server 2016 Hyper-V host. 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.

There are two ways to run PowerShell Direct:

  • Create and exit a PowerShell Direct session using PSSession cmdlets

  • Run script or command with the Invoke-Command cmdlet

If you're managing older virtual machines, use Virtual Machine Connection (VMConnect) or configure a virtual network for the virtual machine.

Create and exit a PowerShell Direct session using PSSession cmdlets

  1. On the Hyper-V host, open Windows PowerShell as Administrator.

  2. Use the Enter-PSSession cmdlet to connect to the virtual machine. Run one of the following commands to create a session by using the virtual machine name or GUID:

    Enter-PSSession -VMName
    Enter-PSSession -VMGUID
  3. Type your credentials for the virtual machine.

  4. Run whatever commands you need to. These commands run on the virtual machine that you created the session with.

  5. When you're done, use the Exit-PSSession to close the session.

    Exit-PSSession

Run script or command with Invoke-Command cmdlet

You can use the Invoke-Command cmdlet to run a pre-determined set of commands on the virtual machine. Here is an example of how you can use the Invoke-Command cmdlet where PSTest is the virtual machine name and the script to run (foo.ps1) is in the script folder on the C:/ drive:

Invoke-Command -VMName PSTest -FilePath C:\script\foo.ps1

To run a single command, use the -ScriptBlock parameter:

Invoke-Command -VMName PSTest -ScriptBlock { cmdlet }

What's required to use PowerShell Direct?

To create a PowerShell Direct session on a virtual machine,

  • The virtual machine must be running locally on the host and booted.

  • You must be logged into the host computer as a Hyper-V administrator.

  • You must supply valid user credentials for the virtual machine.

  • The host operating system must run at least Windows 10 or Windows Server 2016.

  • The virtual machine must run at least Windows 10 or Windows Server 2016.

You can use the Get-VM cmdlet to check that the credentials you're using have the Hyper-V administrator role and to get a list of the virtual machines running locally on the host and booted.

See Also

Enter-PSSession
Exit-PSSession
Invoke-Command

  • IN THIS ARTICLE
  • Create and exit a PowerShell Direct session using PSSession cmdlets
  • Run script or command with Invoke-Command cmdlet
  • What's required to use PowerShell Direct?
  • See Also
(c) 2016 Microsoft