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!
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
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.
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!
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
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
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:
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
yep I just discovered a few minutes ago that the netw variable was incorrect.
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
Again, thanks for being there for us Luc, I believe I am all set!!!
p.s. For those who don't know it, the network name is case sensitive.