VMware Cloud Community
TheVMinator
Expert
Expert
Jump to solution

Syntax for Reporting VM Network configuration and permissions

Can someone recommend the proper syntax for this:How would I add the information on the network configuration (IP4 address) and permissions (such as user/group, role) to a report? For example, if I start with the command Get-VM | select Name and I want to add columns for IP address, user/group, and role to the output?

Thanks! 


 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If there is only 1 IP address, then it's quite easy.

Something like this

Get-Cluster -Name clustername | Get-VM | select Name,MemoryMB,NumCpu,Description,PowerState,ProvisionedSpaceGB,UsedSpaceGB,Version,VMHost,ResourcePool,
	@{N="HDsizeKB";E={($_.Harddisks | Measure-Object -Property CapacityKB -Sum).Sum}},Folder,
	@{N="Datastore";E={($_ | Get-Datastore).Name}},
	@{N="#Snapshots";E={($_ | Get-Snapshot).Count}},
	@{N="OS Name";E={$_.Guest.OSFullName}},
	@{N="IP address";E={$_.Guest.IPAddress}} | `
	Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture

But note that the guest needs to be powered on and needs to have the VMware Tools installed to see the IP address.

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

Your question apparently got a bit mangled up but I'll try to interprete what I think is asked.

The problem with this query is that you potentialy want to merge two 1-n connections.

A guest can have more than 1 IP address and more than 1 permission.

The following will display the IP addresses as an array (which won't work if you want to use Export-Csv to save the output).

foreach($vm in Get-VM){
	Get-VIPermission -Entity $vm | Select @{N="Name";E={$vm.Name}},
		@{N="IP address";E={$vm.Guest.IPAddress}},
		@{N="Principal";E={$_.Principal}},
		@{N="Role";E={$_.Role}}
}

To avoid the problem with the array of IP addresses, you could concatenate them in 1 string.

I used the .Net Join function for that.

A sample is in the attached file (had to that because the script contains square brackets which the forum SW doesn't like).

Now you can safely export to a CSV file.

____________

Blog: LucD notes

Twitter: lucd22


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

TheVMinator
Expert
Expert
Jump to solution

OK thank you for the info - very helpful. In this case, I need to keep the report to one line of information per VM. Because each VM has only one IP address, if it is possible to get that one IP address in the report and export it, great. As far as permissions, each VM has more than one permission, and unless the list of permissions can somehow be all included in the one line for each VM, then I won't be able to include that information at least on this report.

So here is my script as it stands - to which I am hoping to add one column for IP address and if it can be put on one row, the list of permissions/roles on the VM:

Get-Cluster -Name clustername | Get-VM | select Name,MemoryMB,NumCpu,Description,PowerState,ProvisionedSpaceGB,UsedSpaceGB,Version,VMHost,ResourcePool,

@{N="HDsizeKB";E={($_.Harddisks | Measure-Object -Property CapacityKB -Sum).Sum}},Folder,

@{N="Datastore";E={($_ | Get-Datastore).Name}},@{N="#Snapshots";E={($_ | Get-Snapshot).Count}},

@{N="OS Name";E={$_.Guest.OSFullName}} | Export-Csv "C:\report.csv" -NoTypeInformation

Thanks again

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

If there is only 1 IP address, then it's quite easy.

Something like this

Get-Cluster -Name clustername | Get-VM | select Name,MemoryMB,NumCpu,Description,PowerState,ProvisionedSpaceGB,UsedSpaceGB,Version,VMHost,ResourcePool,
	@{N="HDsizeKB";E={($_.Harddisks | Measure-Object -Property CapacityKB -Sum).Sum}},Folder,
	@{N="Datastore";E={($_ | Get-Datastore).Name}},
	@{N="#Snapshots";E={($_ | Get-Snapshot).Count}},
	@{N="OS Name";E={$_.Guest.OSFullName}},
	@{N="IP address";E={$_.Guest.IPAddress}} | `
	Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture

But note that the guest needs to be powered on and needs to have the VMware Tools installed to see the IP address.

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos