VMware Cloud Community
AndyShine
Enthusiast
Enthusiast
Jump to solution

Syntax : How do I pass the vm name to New-NetworkAdapter?

( Powershell \ VI Toolkit newbie )

I'm trying to add a new network adapter to a powered off vm using the VI Toolkit.

I'm having a problem passing the machine id\name to the New-NetworkAdapter cmdlet. I'm using a vm called DR-Application.

e.g. :

New-NetworkAdapter -NetworkName 'VM Network' -VM DR-application

produces the error:

New-NetworkAdapter : Cannot bind parameter 'VM'. Cannot convert value "Dr-application" to type "VMware.VimAutomation.Ty

pes.VirtualMachine". Error: "Invalid cast from 'System.String' to 'VMware.VimAutomation.Types.VirtualMachine'."

At line:1 char:70

I've also tried

GET-Vm -Name DR-A* | New-NetworkAdapter -NetworkName 'VM

Network' -VM $_

New-NetworkAdapter : Cannot bind argument to parameter 'VM' because it is null.

At line:1 char:70

+ GET-Vm -Name DR-A* | New-NetworkAdapter -NetworkName 'VM Network' -VM <<<< $_

Help!

Thanks

Andrew

0 Kudos
1 Solution

Accepted Solutions
Niket
Enthusiast
Enthusiast
Jump to solution

Hi Andy

Please refer below script to pass the VM name for setting up a New-NetworkAdapter :

$server = Get-VIServer -server

New-NetworkAdapter -VM (Get-VM DR-application) -NetworkName "Target-Network-Name"

Please let me know if you face any issues in running the script

I hope it resolves your issue

Thanks

-Niket

View solution in original post

0 Kudos
5 Replies
halr9000
Commander
Commander
Jump to solution

New-NetworkAdapter -NetworkName 'VM Network' -VM DR-application

I think vmware acknowledged this could be made easier, but you can probably fix it with the addition of a "-vm (get-vm dr-application)".

GET-Vm -Name DR-A* | New-NetworkAdapter -NetworkName 'VM

Network' -VM $_

Here, -vm $_ is redundant and confused the cmdlet. Try the same command without specifying a VM parameter at all, it should get it via the pipeline.

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
Niket
Enthusiast
Enthusiast
Jump to solution

Hi Andy

Please refer below script to pass the VM name for setting up a New-NetworkAdapter :

$server = Get-VIServer -server

New-NetworkAdapter -VM (Get-VM DR-application) -NetworkName "Target-Network-Name"

Please let me know if you face any issues in running the script

I hope it resolves your issue

Thanks

-Niket

0 Kudos
AndyShine
Enthusiast
Enthusiast
Jump to solution

Niket,

Worked perfectly!

Do you know if theres a way to remove unecessary Serial\Parallel\USB Ports using a similar command? I suspect this isn't supported in the this beta of the VI Toolkit...?

Thanks

Andrew

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Have a look at thread


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

AndyShine
Enthusiast
Enthusiast
Jump to solution

LucD,

Thanks for the pointer. I see the thread is based upon a request i made last week Smiley Happy

Unfortunately I don't think I can use this solution. My scripting skills are rather weak so I can barely follow what the script is doing. If I where to use it in my environment I'd probably have difficulty supporting it when the environment changes.

Fortunately my request is not vital to what I'm trying to achieve so I think i'll put this on the back burner and hope the next release of the VI Toolkit gies me the Remove commands I'd like.

Thanks again

Andrew

0 Kudos