none
Changing DNS IPv4 address and change domain name on newly domain joined VM using Powershell

    问题

  • Hi,

    I created a one VM and installed DNS, DC on it. I also created another virtual machine by domain joined to DC machine created first.

    The Power shell script follows

    $dns = New-AzureDns -Name 'testdc.com' -IPAddress '10.79.10.1'
    
    $pass = 'password@123'
    $iisimage = 'MSFT__Windows-Server-2012-Datacenter-201208.01-en.us-30GB.vhd'
    
    $iisvm1 = New-AzureVMConfig -Name 'Test1' -InstanceSize Small -ImageName $iisimage |
    	Add-AzureProvisioningConfig -WindowsDomain -Password 'password@123' -Domain 'testdc' -DomainPassword 'password@123' -DomainUserName 'testdc.com\administrator' -JoinDomain 'testdc.com' -MachineObjectOU 'OU=TTESTDC,DC=testdc,DC=com' | 	
    	Set-AzureSubnet -SubnetNames 'FrontEndSubnet'
    	
    New-AzureVM -ServiceName 'Web1' -VMs $iisvm1,  -AffinityGroup 'West Europe' -VNetName 'TestVPC' -DnsSettings $dns

    Now, I need to change the DNS IPv4 address of the newly created machine to the DC VM IP Address and also change the machine to join to the domain by changing from workgroup to domain using Powershell script. I could able to do that from GUI, but need to know from Powershell.

    I tried to use Set-DnsClientServerAddress, but not sure how to run this script for a remote computer and which his again not in the domain yet. I tried to get the VM using New-CimSession, but  this works fine only when the domain is under domain controller and the DNS is set before.

    Please let me know how to change the DNS and join domain from remote machine.

    2012年10月16日 10:39

全部回复

  • Hello,

    Thank you for posting your question here.

    Currently, the DNS client settings can only be set while the VM is provisioned. Step 6 of this article explains how to do it:

    Install a Replica Active Directory Domain Controller in Windows Azure Virtual NetworkS

    Step 6: Provisioning a Virtual Machine that is Domain Joined on Boot

    Let me know if that is useful or if you have follow up questions.

    Regards,
    -Steve

    2012年10月16日 16:52
    版主
  • Hi,

    The Step 6 (Provisioning a VM that is domain Join on boot) is what I have done with the script. Please review the Powershell script posted in the question.

    But once the VM created, I can ping other machine from the DC. But when login in the new VM which is domain join on boot, I could not see the DNS address updated and that machine is joined in the domain (still in workgroup).

    Please let me know the Step 6 works in this way as expected (means the DNS IPv4 address and domain not updated). I want to change these properties from powershell from DC. Please let me know is it possible.

    2012年10月17日 5:37
  • Hi,

    Your script is incomplete since it doesn't create a VM

    The DNS settings cannot be changed. The DNS client settings can only be set when the time the VM is created.

    Step 6 of this article explains it better than Step 6 of the other article:

    Install a new Active Directory forest in Windows Azure

    Step 6: Provisioning a Virtual Machine that is Domain Joined on Boot

    Note the New-AzureVM cmdlet, copied here for your convenience: 

    # # Point to IP Address of Domain Controller Created Earlier $dns1 = New-AzureDns -Name 'dc-name' -IPAddress 'IP ADDRESS' # Configuring VM to Automatically Join Domain $advm1 = New-AzureVMConfig -Name 'advm1' -InstanceSize Small -ImageName $imgname | Add-AzureProvisioningConfig -WindowsDomain -Password '[YOUR-PASSWORD]' ` -Domain 'contoso' -DomainPassword '[YOUR-PASSWORD]' ` -DomainUserName 'administrator' -JoinDomain 'contoso.com' | Set-AzureSubnet -SubnetNames 'AppSubnet' # New Cloud Service with VNET and DNS settings New-AzureVM –ServiceName 'someuniqueappname' -AffinityGroup 'adag' ` -VMs $advm1 -DnsSettings $dns1 -VNetName

    #
    -Steve



    2012年10月18日 17:50
    版主
  • Hi Steve,

    Thanks for your answer. But I still confused where I am making mistake. The script you had given and mine are same. Please refer the following script where I commented with four # for comparing my script.

    # # Point to IP Address of Domain Controller Created Earlier  
    $dns1 = New-AzureDns -Name 'dc-name' -IPAddress 'IP ADDRESS'
    
    ####$dns = New-AzureDns -Name 'testdc.com' -IPAddress '10.79.10.1'
    
    
    $pass = 'password@123'
    $iisimage = 'MSFT__Windows-Server-2012-Datacenter-201208.01-en.us-30GB.vhd'
    
    # Configuring VM to Automatically Join Domain 
    $advm1 = New-AzureVMConfig -Name 'advm1' -InstanceSize Small -ImageName $imgname | 
    	Add-AzureProvisioningConfig -WindowsDomain -Password '[YOUR-PASSWORD]' ` -Domain 'contoso' -DomainPassword '[YOUR-PASSWORD]' ` -DomainUserName 'administrator' -JoinDomain 'contoso.com' | 
    	Set-AzureSubnet -SubnetNames 'AppSubnet' 
    
    
    ####$iisvm1 = New-AzureVMConfig -Name 'Test1' -InstanceSize Small -ImageName $iisimage |
    ####	Add-AzureProvisioningConfig -WindowsDomain -Password 'password@123' -Domain 'testdc' -DomainPassword 'password@123' -DomainUserName 'testdc.com\administrator' -JoinDomain 'testdc.com' -MachineObjectOU 'OU=TTESTDC,DC=testdc,DC=com' | 	
    ####	Set-AzureSubnet -SubnetNames 'FrontEndSubnet'
    	
    # New Cloud Service with VNET and DNS settings
    New-AzureVM –ServiceName 'someuniqueappname' -AffinityGroup 'adag' ` -VMs $advm1 -DnsSettings $dns1 -VNetName 
    
    ####New-AzureVM -ServiceName 'Web1' -VMs $iisvm1,  -AffinityGroup 'West Europe' -VNetName 'TestVPC' -DnsSettings $dns
    

    My requirement is, after I created the VM by using this script I need to login to the VM and change the IPV4 address of the network (Ethernet) and change the domain name from workgroup to join the domain. I need that to be done by script itself while creating.
    2012年10月25日 12:40
  • Hi,

    I'll do my best to debug that for you. It would help if I knew what error or behavior you were seeing when you try it.

    On the surface your code (with four #) looks ok but I'm making assumptions about your environment like the existence and spelling on the Affinity Group and the uniqueness of the ServiceName.

    One thing that I noticed after that is that the New-AzureVM command is incomplete but I suspect that was intentional.

    You try testing without -MachineObjectOU. I wonder if TTESTDC is supposed to have that many Ts in it.

    Again, error messages and observed behaviors would be helpful.

    -Steve

    2012年10月29日 23:34
    版主