Thursday, October 8, 2015

vmware esx vm ip address and mac address

 three scripts. data oh so differs.  
   
 script1  
   
 $LOG_FILE = "C:\machines.txt"  
 get-vm | %{ $_ | select Name, @{N="IP Address";E={@($_.guest.IPAddress[0])}} | out-file -filepath $LOG_FILE -append; $_ | Get-NetworkAdapter | out-file -filepath $LOG_FILE -append }  
   
 script2  
   
 $VMs = get-vmhost | Get-VM  
 foreach ($VM in $VMs){  
   $VMx = Get-View $VM.ID  
    $HW = $VMx.guest.net  
    foreach ($dev in $HW)  
   {  
     foreach ($ip in $dev.ipaddress)  
     {  
       $dev | select  
       @{Name = "Name"; Expression = {$vm.name}},  
       @{Name = "IP"; Expression = {$ip}},  
       @{Name = "MAC"; Expression = {$dev.macaddress}} |  
       Export-CSV C:\vmwaremacip2.csv -NoTypeInfo  
         
    
     }  
   }  
 }  
   
 script3  
   
 Get-View -ViewType virtualmachine |   
 Select Name, @{N="MAC";E={((Get-VM $_.Name).NetworkAdapters).MacAddress}},  
  @{N="IP";E={$_.Summary.Guest.IpAddress}} |  
 Export-Csv -NoTypeInformation -UseCulture -Path C:\vmwaremacip3.csv  
   

No comments: