===Find subnet a VM is in using VMware Tools:===
$vm = Get-VM
$vm.ExtensionData.Guest.Net | Select @{N="VM";E={$vm.Name}},MacAddress,Network,
@{N="DHCP";E={$_.IpConfig.Dhcp.Ipv4.Enable}},
@{N="IP";E={$_.IpAddress[0]}},
@{N="CIDR Notation";E={$_.IpConfig.IpAddress[1].PrefixLength}},
@{N="Subnet Mask";E={
$dec = [Convert]::ToUInt32($(("1" * $_.IpConfig.IpAddress[0].PrefixLength).PadRight(32, "0")), 2)
$DottedIP = $( For ($i = 3; $i -gt -1; $i--) {
$Remainder = $dec % [Math]::Pow(256, $i)
($dec - $Remainder) / [Math]::Pow(256, $i)
$dec = $Remainder
} )
[String]::Join('.', $DottedIP)
}}
===Get a csv file listing all VMs and their tags===
Get-VM |
Select-object Name,
@{N = 'vCenter'; E = {([system.uri]$_.ExtensionData.Client.ServiceUrl).Host}},
@{N = 'Tags'; E = {(Get-TagAssignment -Entity $_).Tag -join '|'}},
PowerState, Notes, Guest, NumCpu, CoresPerSocket, MemoryMB, MemoryGB, VMHostId, VMHost,
Folder, Version, GuestId, UsedSpaceGB, ProvisionedSpaceGB |
Export-Csv -path “c:\Temp\tags.csv” –NoTypeInformation -UseCulture