bvi1006
Enthusiast
Enthusiast

Setting the network name on a nic before the customization spec

Hi,

I am building a virtual machine using a customization spec in which I want to join the domain. If the command below requires the vm to be powered on, how can I get this done before the customization spec tries to join the domain? I need it to be on a particular network of course.

get-networkadapter $servername | set-networkadapter -networkname $netw -Confirm:$false -StartConnected:$true -Connected:$true

Thanks!

0 Kudos
7 Replies
LucD
Leadership
Leadership

Afaik the VM doesn't need to be powered on to use the Set-NetworkAdapter cmdlet.
Unless you are seeing the contrary?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
bvi1006
Enthusiast
Enthusiast

Yes, it gave me an error message that it had to be powered on. I will try it again tomorrow and paste in the error message.

Thanks Luc.

0 Kudos
bvi1006
Enthusiast
Enthusiast

Here is the message:

get-networkadapter $servername | set-networkadapter -networkname $netw -Confirm:$false -StartConnected:$true -Connected:$true

set-networkadapter : 10/29/2018 4:58:45 PM    Set-NetworkAdapter        The VM must be in the following state: PoweredOn.   

At line:1 char:34

+ get-networkadapter $servername | set-networkadapter -networkname $netw -Confirm: ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (PoweredOff:PowerState) [Set-NetworkAdapter], ViError

    + FullyQualifiedErrorId : Common_SharedParameterHelper_VerifyVmIsInState_VmNotInState,VMware.VimAutomation.ViCore.Cmdlets.

   Commands.VirtualDevice.SetNetworkAdapter

Thanks!

0 Kudos
LucD
Leadership
Leadership

That is due to the Connected switch (which in fact doesn't make much sense when the VM is powered off)

If you leave that one out, the VM can be powered off.

Get-NetworkAdapter $servername |

Set-NetworkAdapter -NetworkName $netw -Confirm:$false -StartConnected:$true


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
bvi1006
Enthusiast
Enthusiast

Thanks, I tried that. But what I am really trying to do is change the network. I build the vm, power it on, and want it to be customized on a particular network as opposed to the one the template is connected to....

C:\Windows\system32> get-networkadapter $servername | set-networkadapter -networkname $netw -Confirm:$false

set-networkadapter : 10/30/2018 8:29:00 AM    Set-NetworkAdapter        Object reference not set to an instance of an object. 

 

At line:1 char:34

+ get-networkadapter $servername | set-networkadapter -networkname $netw -Confirm: ...

+                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Set-NetworkAdapter], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetwo

   rkAdapter

0 Kudos
LucD
Leadership
Leadership

Why do you power on the VM before you set the networkname?

When you want to change the network from the template, there are 2 steps:

  • connect the VM to another portgroup (what the Set-NetworkAdapter is doing, and which doesn't need the VM to be powered on)
  • change the network inside the guest OS (and for that the VM obviously needs to be powered on)

The error you are getting seems to be related to the $netw variable.

Are you perhaps trying to connect the VM to a portgroup on a distributed switch?

In that case you should use the Portgroup parameter.

In fact always use the Portgroup parameter, that works for a a VSS as well as for VDS portgroup.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
bvi1006
Enthusiast
Enthusiast

yep I just discovered a few minutes ago that the netw variable was incorrect. Smiley Happy

I was trying to change the network before powering it on, but was getting that error message about the vm needing to be in the powered on state. So that blew my whole logic of trying to do it before the customization. Then I went down the rabbit hole and thought my logic was not going to work Smiley Happy

Again, thanks for being there for us Luc, I believe I am all set!!!

Smiley Happy

p.s. For those who don't know it, the network name is case sensitive.

0 Kudos