I'm trying to determine the networks available to vm's in my cluster. If I run a powershell script with this in it...
Connect-VIServer ServerName
$net = Get-NetworkAdapter -VM "TestVM"
echo $net
MacAddress : 00:50:56:88:02:ed
WakeOnLanEnabled : True
NetworkName : Network1
Type : Flexible
ConnectionState : VMware.VimAutomation.Client20.ConnectInfoImpl
Id : VirtualMachine-vm-594/4000
Name : Network Adapter 1
MacAddress : 00:50:56:98:46:18
WakeOnLanEnabled : True
NetworkName : Network2
Type : Flexible
ConnectionState : VMware.VimAutomation.Client20.ConnectInfoImpl
Id : VirtualMachine-vm-594/4001
Name : Network Adapter 2
My question is, how can I input the value of NetworkName into a variable so that I can do a comparison? Or is there a better way to get the values of NetworkName?
If your just trying to output the network adapters attached to your vms then using your current script you could do this:
$net = Get-NetworkAdapter -VM "vpedhcp01"
foreach ($networkadapter in $net) {echo $networkadapter.NetworkName}
Are you trying to list each VM in a cluster and then the networks attached to the VM, if so this is fairly easy too?
If you found this information useful, please consider awarding points for Correct or Helpful.
Alan Renouf
I can't really get your question but hope this helps:
$networkName = "Network1"
$net = Get-NeetworkAdapter -Vm "TestVm" | where {$_.NetworkName -eq $networkName}