Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 175326

Virtual Servers Networknames to a file

$
0
0

Hi all!

 

I would like to extract information from virtual servers and to which Portgroup/Networkname their Network adapters are connected to. The virtual servers might have one or more Network adapters, the output should be sent to a csv file and with one column per Networkname. I use the below code and it seems to work fine, but if the Virtual server have two or more Network adapters it will list all "Networkname" in the same column and that is not what I want...My skills in PowerCLI is quite poor so I am having difficulties to solve this............Thanks a lot in advance.

 

 

 

$portreport = @()

$VMs = Get-VMHost -Name $VMhost | Get-VM

 

 

foreach ($VM in $VMs){

 

    $VMportinfo = "" | Select VMName, Networkname

   

 

    #VMName

      $VMportinfo.VMName = $VM.Name

   

    #Networkname

   

    $NicNetName = Get-NetworkAdapter -VM $VM | ForEach-Object {$_.NetworkName}

   

    $VMportinfo.Networkname =[string]$NicNetName

     

   

        $portreport += $VMportinfo

 

}

 

    $portreport | Export-Csv D:\scripts\Networkname.csv -NoTypeInformation


Viewing all articles
Browse latest Browse all 175326

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>