VMware Cloud Community
dbutch1976
Hot Shot
Hot Shot
Jump to solution

Network customization using powerCLI

Hello all,

I'm brand new to scripting and I'm not sure why I seem to have to run these two commands separately:

get-vm "MYTESTVM" | Get-VMGuestNetworkInterface -Guestuser Administrator -GuestPassword MYPASSWORD |?{$_.name -eq "Local Area connection 4"} | set-vmguestnetworkinterface -Guestuser Administrator -GuestPassword MYPASSWORD -IPPolicy static -IP 10.244.186.113 -Netmask 255.255.255.0 -Gateway 10.244.186.1 -DNS 10.244.37.25,10.244.37.26

Get-NetworkAdapter "TEST-SVR01" | Set-NetworkAdapter -NetworkName VLAN186_QA -Confirm:$false

The code works if I run it line by line.  But it doesn't work if I try this:

get-vm "MYTESTVM" | Get-VMGuestNetworkInterface -Guestuser Administrator -GuestPassword MYPASSWORD |?{$_.name -eq "Local Area connection 4"} | set-vmguestnetworkinterface -Guestuser Administrator -GuestPassword MYPASSWORD -IPPolicy static -IP 10.244.186.113 -Netmask 255.255.255.0 -Gateway 10.244.186.1 -DNS 10.244.37.25,10.244.37.26 | Get-NetworkAdapter "TEST-SVR01" | Set-NetworkAdapter -NetworkName VLAN186_QA -Confirm:$false

Any suggestions?

Thanks.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The object that Set-VMGuestNetworkInterface places on the pipeline, is not an object that Get-NetworkAdapter expects on the pipeline.

The 1st cmdlet sends 1 or more VMGuestNetworkInterface objects.

The 2nd cmdlet expects a VM, Template or Related Object on the pipeline.


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

View solution in original post

0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

The object that Set-VMGuestNetworkInterface places on the pipeline, is not an object that Get-NetworkAdapter expects on the pipeline.

The 1st cmdlet sends 1 or more VMGuestNetworkInterface objects.

The 2nd cmdlet expects a VM, Template or Related Object on the pipeline.


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

0 Kudos
dbutch1976
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

I believe I understand you.  Are you saying that these two cmdlets cannot be run on the same line and need to be run seperately since they expect objects placed on the pipe?

Thanks.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Indeed.


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

0 Kudos