VMware {code} Community
ISYS2
Enthusiast
Enthusiast

Get list of Networks in Datacenter using Powershell

I need to get a list of VM Folders, Datastores and Networks from a VirtualCenter. I am using Powershell.

I can get the list of folders using Get-Folder and I use the following to get the list of datastores

$dc = Get-Datacenter | get-view

foreach($dstore in $dc.Datastore){

$dstr = Get-VIObjectByVIView $dstore

Write-Host $dstr

}

If I use the same logic and try converting the MOR of $dc.Networks to a variable I keep getting blank results. I get as many blanks as there are networks in the Datacenter.

Any ideas?

Thanks

0 Kudos
4 Replies
MattG
Expert
Expert

Have you looked at VESI (thevesi.org) yet? This is a modification of PowerGui written to better manage virtual environments. It will easily produce this info as output and the underlying Powershell code.

-MattG

-MattG If you find this information useful, please award points for "correct" or "helpful".
0 Kudos
ISYS2
Enthusiast
Enthusiast

Thanks for the reply MattG

I haven't tried this as the problem lies with the powershell code itself, not the editor. I am producing a tool for a production environment. The tool has to be based on an Excel spreadsheet and therefore the majority of the code is written using VBA which in turn produces powershell scripts on the fly and runs them. The results of the powershell are re-imported back in to the Excel spreadsheet.

As I stated this is for a production environment and therefore I can only use native Powershell and I am unable to use third party tools.

Regards

0 Kudos
MattG
Expert
Expert

So you cant use the VI-Toolkit's Powershell?

-MattG

-MattG If you find this information useful, please award points for "correct" or "helpful".
0 Kudos
jeffpatton
Enthusiast
Enthusiast

I had a similar need, and while it's almost a full 2yrs after the original post, I wrote up a script that returns a list of networks on a specific VMHost.

The script is available at my site, https://github.com/jeffpatton1971/mod-posh/blob/master/powershell/production/includes/VMwareManageme... the function is Get-VMHostNetworks.

I believe this particular function does exactly what the original poster requested using powershell cmdlets from vmware.

Message was edited by: Jeff Patton Updated the URL for where my stuff is located.

Jeffrey S. Patton Systems Specialist, Enterprise Systems University of Kansas 1001 Sunnyside Ave. Lawrence, KS. 66045 http://patton-tech.com
0 Kudos