tasoss
Contributor
Contributor

changing guest operating system's nic details via c# using CustomizeVM_Task

Hello.I would like to change for example the ip address of a nic on the guest operating system.

  CustomizationSpec customsSpec2 = new CustomizationSpec();

         

            CustomizationAdapterMapping adapterMap = new CustomizationAdapterMapping();

            CustomizationIPSettings adapter = new CustomizationIPSettings();

            CustomizationFixedIp fixedIP = new CustomizationFixedIp();

            fixedIP.IpAddress = "192.168.2.83";

            adapter.Ip = new CustomizationIpGenerator();

            adapter.Gateway = new string[] {"192.168.2.3"};

         

            adapterMap.Adapter = adapter;

            adapterMap.Adapter.Ip = fixedIP;

            adapterMap.Adapter.SubnetMask = "255.255.255.0";

            customsSpec2.NicSettingMap = new CustomizationAdapterMapping[] { adapterMap };

            var custwinoptions = new CustomizationWinOptions();

            customsSpec2.Options = custwinoptions;

         

            customsSpec2.GlobalIPSettings = new CustomizationGlobalIPSettings();

         

            var idid=new CustomizationSysprep();

            idid.Identification = new CustomizationIdentification();

            //idid.Identification.DomainAdmin = "";

            //idid.Identification.

         

            idid.GuiUnattended=new CustomizationGuiUnattended();

         

            idid.GuiUnattended.AutoLogon = true;

         

            idid.UserData = new CustomizationUserData();

            var custname = new CustomizationVirtualMachineName();

            idid.UserData.ComputerName = custname;

            idid.UserData.FullName = "userdataFullName";

            idid.UserData.OrgName = "userDataOrgName";

            idid.UserData.ProductId = "";

           customsSpec2.Identity = idid;

            var cName = new CustomizationName();

           customizeVMTask = targetVirtualMachine.CustomizeVM_Task(customsSpec2);

Then i had to insert the sysprep files in the appropriate directory....

After a lot of pain and tears(lol) i managed to change the ip address.

My questions

a)Is Sysprep the only solution in order to change info on the guest operating system ?

b)By using the method above i had to power on the machine twice i think.Then i had to enter a few options(i suppose i didn't complete all of them although i had used GuiUnattended)

c)The other solution is to use powercli?Which  i have seen that works in linux too via perl.

d)Isn't an easier way to change the ip address of a nic ?????Is there any way call whatever  Set-VMGuestNetworkInterface calls via c# without using powershell ?

Somebody please answer.

Thanks.

0 Kudos
0 Replies