VMware Cloud Community
WallaceTechUK
Contributor
Contributor
Jump to solution

Set-NetworkAdapter - Object reference not set to an instance of an object.

Guys.

I have moved a whole bunch of VM's from one cluster that had a Standard vSwitch to a cluster than has a Distributed vSwitch. Now I am banging my head againt the wall with this one. I thought the code below would work but i get a message

Set-NetworkAdapter   

Object reference not set to an instance of an object.

What am i doing wrong here?

--------------

Connect-VIServer SERVER1

$OldNetwork = "EU VDI ILIO Storage Network"

$NewNetwork = "EU UCS VDI Port Group(VDI Desktops - VLAN148)"

Get-VM |Get-NetworkAdapter |Where {$_.NetworkName -eq $OldNetwork } |Set-NetworkAdapter -NetworkName $NewNetwork -Confirm:$false

Reply
0 Kudos
1 Solution

Accepted Solutions
pkolom
Enthusiast
Enthusiast
Jump to solution

Strange.. it works for me, however I used double quotes and I don't have spaces in dVportgroup names:

$myNetworkAdapters = Get-VM wintest1 | Get-NetworkAdapter -Name "Network adapter 1"

myVDPortGroup = Get-VDPortgroup -Name "v4094--BLACK_HOLE"

Set-NetworkAdapter -NetworkAdapter $myNetworkAdapters -Portgroup $myVDPortGroup

try with oneliner (sorta, you'll still need myVDportGroup variable):

$myVDPortGroup = Get-VDPortgroup -Name "EU VDI Workstations PortGroup"

Get-VM Test| Get-NetworkAdapter -Name "Network adapter 1" |Set-NetworkAdapter -Portgroup $myVDPortGroup

If still unsuccessful, please provide output of "get-member" command against your variables (gm is an alias):

$myNetworkAdapters|gm

$myVDPortGroup|gm

View solution in original post

Reply
0 Kudos
11 Replies
Grzesiekk
Expert
Expert
Jump to solution

--------------  Example 4 --------------

C:\PS>$myNetworkAdapters = Get-VM | Get-NetworkAdapter -Name "Network adapter 1"

$myVDPortGroup = Get-VDPortgroup -Name MyVDPortGroup

Set-NetworkAdapter -NetworkAdapter $myNetworkAdapters -Portgroup $myVDPortGroup

Retrieves all network adapters named "Network adapter 1" from all virtual machines and connects them to the specified distributed port group.

--- @blog https://grzegorzkulikowski.info
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Which PowerCLI version are you using ?

Do a Get-PowerCLIVersion

What does

Get-VM |Get-NetworkAdapter

show after the move to the other cluster, more specifically on the NetworkName property ?


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

Reply
0 Kudos
WallaceTechUK
Contributor
Contributor
Jump to solution

Hello. Thanks for the replay.

Get-VM Test | Get-NetworkAdapter -Name "Network adapter 1"  - Returns correct info

Get-VDPortgroup -Name "EU VDI Workstations PortGroup" - Returns the correct Port Group info

When I run all the script together i get the message below.

Set-NetworkAdapter : 09/09/2015 08:55:25Set-NetworkAdapter    The specified DV portgroup 'EU VDI Workstations

PortGroup' can not be used for vnic connection: Invalid portgroup type

--------------

$myNetworkAdapters = Get-VM Test | Get-NetworkAdapter -Name "Network adapter 1"

#

$myVDPortGroup = Get-VDPortgroup -Name "EU VDI Workstations PortGroup"

#

Set-NetworkAdapter -NetworkAdapter $myNetworkAdapters -Portgroup $myVDPortGroup

Reply
0 Kudos
pkolom
Enthusiast
Enthusiast
Jump to solution

Blind gues: maybe you receive this error, because one of the portgroup is vmkernel only?

Reply
0 Kudos
WallaceTechUK
Contributor
Contributor
Jump to solution

Hello.

My VMKernel is not on any of the distributed switches.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Can you try placing the portgroup names between single quotes ?

It might be that the parenthesis are interpreted as meta characters


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

Reply
0 Kudos
WallaceTechUK
Contributor
Contributor
Jump to solution

Thank you.

Still the same issue and error message

Set-NetworkAdapter : 09/09/2015 15:51:14Set-NetworkAdapter    The specified DV portgroup 'EU VDI Workstations

PortGroup' can not be used for vnic connection: Invalid portgroup type.   

Changed Script

-----------------------------------

$myNetworkAdapters = Get-VM Test | Get-NetworkAdapter -Name 'Network adapter 1'

$myVDPortGroup = Get-VDPortgroup -Name 'EU VDI Workstations PortGroup'

Set-NetworkAdapter -NetworkAdapter $myNetworkAdapters -Portgroup $myVDPortGroup

Reply
0 Kudos
WallaceTechUK
Contributor
Contributor
Jump to solution

OK.

I have been a bit of a dick. I was connecting directley to the host and not to vCenter. I was trying to be safe and only deal with my test host. Thinking about it now i should have been connecting the the vCenter.  However the issue i have now is this,

Code

-----

$myNetworkAdapters = Get-VM Test | Get-NetworkAdapter -Name 'Network adapter 1'

$myVDPortGroup = Get-VDPortgroup -Name 'EU VDI Workstations PortGroup'

Set-NetworkAdapter -NetworkAdapter $myNetworkAdapters -Portgroup $myVDPortGroup

Error message

-----

Get-NetworkAdapter : The input object cannot be bound to any parameters for the command either because the command does not take pipeline

input or the input and its properties do not match any of the parameters that take pipeline input.

Reply
0 Kudos
pkolom
Enthusiast
Enthusiast
Jump to solution

Strange.. it works for me, however I used double quotes and I don't have spaces in dVportgroup names:

$myNetworkAdapters = Get-VM wintest1 | Get-NetworkAdapter -Name "Network adapter 1"

myVDPortGroup = Get-VDPortgroup -Name "v4094--BLACK_HOLE"

Set-NetworkAdapter -NetworkAdapter $myNetworkAdapters -Portgroup $myVDPortGroup

try with oneliner (sorta, you'll still need myVDportGroup variable):

$myVDPortGroup = Get-VDPortgroup -Name "EU VDI Workstations PortGroup"

Get-VM Test| Get-NetworkAdapter -Name "Network adapter 1" |Set-NetworkAdapter -Portgroup $myVDPortGroup

If still unsuccessful, please provide output of "get-member" command against your variables (gm is an alias):

$myNetworkAdapters|gm

$myVDPortGroup|gm

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you check that 'Get-VM Test' actually returns something ?


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

Reply
0 Kudos
WallaceTechUK
Contributor
Contributor
Jump to solution

Odd.

Using your code below works for me. I am trying to see what is different about it all. Want to see where i went wrong or what i missed.

$myNetworkAdapters = Get-VM wintest1 | Get-NetworkAdapter -Name "Network adapter 1" 

myVDPortGroup = Get-VDPortgroup -Name "v4094--BLACK_HOLE" 

Set-NetworkAdapter -NetworkAdapter $myNetworkAdapters -Portgroup $myVDPortGroup 

Thank you for taking the time to help me on this issue. its very very much appriciated.

Reply
0 Kudos