guesmi1977
Contributor
Contributor

get the name of Vnic from windows to pwercli

hello 
I need to get the name of Vnic (normally named :ethernetx) from windows to pwercli 
can any one help me please

Reply
0 Kudos
LucD
Leadership
Leadership

Try something like this.
You will have to provide credentials for an account that can logon to the Windows OS.

$user = 'domain\user'
$pswd = 'VMware1!'

$cred = New-Object -TypeName PSCredential -ArgumentList $user,(ConvertTo-SecureString -String $pswd -AsPlainText -Force)

$code = @'
Get-NetAdapter | Select Name,@{N='MacAddress';E={$_.MacAddress.Replace('-',':')}} | ConvertTo-Csv
'@

Get-VM -PipelineVariable vm |
ForEach-Object -Process {
  $result = Invoke-VMScript -ScriptText $code -VM $vm -GuestCredential $cred
  Get-NetworkAdapter -VM $vm -PipelineVariable vnic |
  Select @{N='VM';E={$vm.Name}},
    Name,
    @{N='OSName';E={$result.ScriptOutput | ConvertFrom-Csv | where{$_.MacAddress -eq $vnic.MacAddress} | Select -expandProperty Name}}
}


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

Reply
0 Kudos
guesmi1977
Contributor
Contributor

Thank you LucD

I'll test this

Reply
0 Kudos