none
HyperV - HOW TO CONNECT REMOTELY FROM A WORKGROUP-BASED COMPUTER

    Question

  • Hi,

    I'm trying to control remotely a VM called tempDC1 (which belongs to a WORKGROUP) by a HyperVHost called hyperv54 (Belongs to a domain), I mean that both remote VM and hyperv host are not belongs to the same domain/workgroup.

    Note: I have read the "HOW TO CONNECT REMOTELY FROM A WORKGROUP-BASED COMPUTER" section of the about_remote_troubleshooting file.

    I ran the following script:

    $TestAdminCred1 = New-Object System.Management.Automation.PSCredential -ArgumentList "TEMPDC1\Administrators",$("VMPassword" | ConvertTo-SecureString -AsPlainText -Force)
    set-item wsman:\localhost\Client\TrustedHosts -Credential $TestAdminCred1 -Value tempDC1 -Force
    
    get-item wsman:\localhost\Client\TrustedHosts

    1) How can I refere to the host name (hyperv54) using the above script?

    2) How can I execute a function (For example, set IP address) on tempDC1 remotely? I'm not asking you about the script itself, but I'm asking you about how to execute it on tempDC1.


    Please, I need your help,

    Regards,

    Bader


    • Edited by Nadim2522 Thursday, March 08, 2012 8:09 AM
    Thursday, March 08, 2012 8:03 AM

Answers

All replies

  • If you want to remotely execute commands on a server you can use the invoke-command cmdlet. Here is an example of how to use it:

    invoke-command -computername hyperv54 -credential $testadmincred1 -scriptblock { enter what you want to execute between the squiggly brackers }

    Does that do what you want? You can also use this method to call netsh, which allows you to set the IP address of the server. Be careful not to set the IP address to something that is unreachable for the host otherwise you will not be able to execute any further commands.

    Thursday, March 08, 2012 8:14 AM
  • Hi,

    Thank you very much for your reply,

    I used the following code which set an IP address:

    #Set the IP address, MAC address and DNS 
    function Set-IPAddress {  
    param( [string]$networkinterface = "Contoso",  
    [string]$ip = "192.168.0.1",  
    [string]$mask = "255.255.255.0",  
    [string]$dns1 = "127.0.0.1"  
    )  
    #Start writing code here  
    $dns = "127.0.0.1"  
    if($dns2){$dns =$dns1}  
    $index = (gwmi Win32_NetworkAdapter | where {$_.netconnectionid -eq $networkinterface}).InterfaceIndex  
    $NetInterface = Get-WmiObject Win32_NetworkAdapterConfiguration | where {$_.InterfaceIndex -eq $index}  
    $NetInterface.EnableStatic($ip, $mask)  
    $NetInterface.SetDNSServerSearchOrder($dns)  
    }  
      
    $TestAdminCred1 = New-Object System.Management.Automation.PSCredential -ArgumentList "TEMPDC1\Administrators",$("VMPassword" | ConvertTo-SecureString -AsPlainText -Force)
    invoke-command -computername tempDC1 -Credential $TestAdminCred1 -scriptblock { Set-IPAddress }

    But I get the following error message:

    How can I refere to the hyperv54 host using the invoke-command?

    Please, I need your help,

    Regards,

    Bader


    • Edited by Nadim2522 Thursday, March 08, 2012 8:33 AM
    Thursday, March 08, 2012 8:32 AM
  • Your problem is that the server cannot be contacted on the hostname you specified. A connection should be available between the devices otherwise you are not able to execute commands remotely. So in my view you now have two options:

    • Troubleshoot the name resolution
    • Connect using IP address

    I would advise you to first look into the name resolution as that seems to be the easier fix. Remoting by IP address requires additional configuration steps.

    Thursday, March 08, 2012 8:42 AM
  • Hi,

    Below is a sample topology of my servers. I have permission to run the script only from MainHost. the MainHost server has a HyperV Manager, so I can see all VMs that belongs to Hyperv54 and HyperV56 hosts. Also, I can control that VMs without facing any problem (For example, adding NICs and other operations). But... by trying to control the VM remotely from MainHost using the script that I posted before, I get the error message.

    Can you please explain how should troubleshoot the name resolution? Please, I need your help,

    Regards,

    Bader

    Thursday, March 08, 2012 8:57 AM
  • Well lets start at the bottom. Can you actually ping tempdc1 from the host you are using to run the invoke-command?
    Thursday, March 08, 2012 9:09 AM
  • If this is a Workgroup network, name resolution will be done by broadcast (netBIOS), or if you have a DNS server, then by DNS.  But you can normally refer to hosts in a workgroup by netbios name (hostname).

    To test this, ping the remote computer by name:

    ping hyperv56


    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Thursday, March 08, 2012 9:10 AM
  • Hi,

    MainHost can ping hyperv56 .

    Note: both MainHost and hyperv56 belongs to the same domain (lets say: contoso.com), but tempDC1 is only a VM which belongs to hyperv56, and he is on a WORKGROUP and according to the requirements I have NOT to join it to the domain.

    I have read the "HOW TO CONNECT REMOTELY FROM A WORKGROUP-BASED COMPUTER" section of the about_remote_troubleshooting file. but I failed to achieve the requirements.

    Please, I need your help.

    Thanks,

    Bader


    • Edited by Nadim2522 Thursday, March 08, 2012 9:24 AM
    Thursday, March 08, 2012 9:22 AM
  • I just want to clear up some terminology:  The VM does not "belong" to the machine hyperv56.  All your machines are on the same physical / virtual network, otherwise NETBIOS name resolution would not work.  In fact, if hyperv56 and your Mainhost are in the same domain, tempDC1 doesn't belong anywhere except in its own workgroup, all alone.

    The documentation you refer to explains how to access a domain computer from a workgroup computer.  You are doing the opposite.  I don't think this should affect credentials, but it is something to bear in mind.


    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Thursday, March 08, 2012 9:40 AM
  • $TestAdminCred1 = New-Object System.Management.Automation.PSCredential -ArgumentList "TEMPDC1\Administrators",...

    Note, you are using the group name "Administrators", not the user name "Administrator"


    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Thursday, March 08, 2012 9:55 AM
  • Hi,

    As I explained before, tempDC1 is stored on hyperv56 (I sayed before "belong").

    I the following script (Ran from MainHost), I'm showing an example of how to create a snapshot for tempDC1 that it is stored on hyperv56. I need your help in order to run scripts remotely on tempDC1 (For example the script of setting the IP address that I posted before) from MainHost (not from hyperv56). The Idea is to keep tempDC1 out of the domain that MainHost and hyperv56 belongs to.

    function CreateVMSnapShot ([string[]]$VMName, [string]$HyperVHost, [string]$SnapShotName) {  
        foreach ($name in $VMName) {  
            Get-VM -Server $HyperVHost -vm  $name | New-VMSnapshot -Confirm:$true -Force 
            sleep 30
            Get-VMSnapshot -vm $name  -Server $HyperVHost -Current | Rename-VMSnapshot -newname $SnapShotName -Force
            while (!(Get-VM -Server $HyperVHost -Name $name)) {sleep 1}  
        }  
    } 
      
    CreateVMSnapShot -VMName 'tempDC1' -HyperVHost 'hyperv56' -SnapShotName "After setting the network adapter"
    
    
    

    Regards,

    Bader

    Thursday, March 08, 2012 10:05 AM
  • So this script shows us that MAINHOST has connectivity to hyper56. What you have yet to show is that you can access tempdc1 from MAINHOST. Can you verify if you can either ping to the ip of tempdc1 or to its hostname. If that is not the case then you will have to configure the virtual switch the tempdc1 is connected to.

    Most likely you will have to give tempdc1 access to a NIC connected to an External hyper-v switch on hyper56. For more information have a look at this post:

    http://blogs.technet.com/b/jhoward/archive/2008/06/17/hyper-v-what-are-the-uses-for-different-types-of-virtual-networks.aspx

    Thursday, March 08, 2012 11:09 AM
  • Good point, Jaap.  You need to ping tempdc1 from mainhost to test connectivity.  As Jaap says, you may need a router if they are on different networks, but what would be easier would be just to assign an adapter on tempdc1 to the same network segment (virtual/real) as the rest of your network.

    Grant Ward, a.k.a. Bigteddy

    What's new in Powershell 3.0 (Technet Wiki)

    Thursday, March 08, 2012 11:20 AM