( 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
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
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)
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
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
Have a look at thread
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Thanks for the pointer. I see the thread is based upon a request i made last week
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