Hello,
I have a script to get Ip address and vm name:
Get-VM | Select Name,VMHost, @{N="IP Address";E={@($_.guest.IPAddress[0])}} |
Export-Csv -NoTypeInformation C:\Users\gemela\Desktop\machine_ip.csv
I get only one IP, I want to get also management ip and backup ip.
Is possible? ideally will be nice to get all IP for each machine.
Thanks
Yes, just add a calculated property
@{N='MAC';E={$_.MacAddress}},
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Tried the below script but got an empty MAC column. Am I missing something here?
Get-VM | Select Name,VMHost, @{N='MAC';E={$_.MacAddress}}, @{N="IP Address";E={@($_.guest.IPAddress[0])}} |
Export-Csv -NoTypeInformation C:\PS\1machine1_ip.csv
Also, is it possible to get every IP/MAC assigned to the farm machines?
Thank you,
I was referring to this script
Get-VM -PipelineVariable VM | ForEach-Object -Process {
$vm.Guest.Nics |
Select @{N='VM';E={$vm.Name}},
@{N='VMHost';E={$vm.VMHost.Name}},
@{N='Network';E={$_.NetworkName}},
@{N="IP Address";E={$_.IPAddress -join '|'}}
} | Export-Csv -NoTypeInformation C:\Users\gemela\Desktop\machine_ip.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This one worked just fine! Thanks a lot, once again!
I know this was made awhile back but i was hoping you could help out again. Could you could remove the host column, add the Guest OS Type, and Powered on State? The rest is working wonderfully but I need those columns for a report I'm building. Your original script that added the IP's into their own columns was almost perfect for what I needed.
$report = foreach($vm in Get-VM){
$obj = [ordered]@{
Name = $vm.Name
Host = $vm.VMHost.Name
}
$i = 1
$vm.Guest.IPAddress | %{
$obj.Add("IP$($i)",$_)
$i++
}
New-Object PSObject -Property $obj
}
$report | Sort-Object -Property {($_ | Get-Member -MemberType Properties).Count} -Descending |
Export-Csv D:\Powershell\Logs\TestIP_1.csv -NoTypeInformation -UseCulture
Try like this
$report = foreach ($vm in Get-VM) {
$obj = [ordered]@{
Name = $vm.Name
PowerState = $vm.PowerState
GuestOS = $vm.Guest.OSFullname
}
$i = 1
$vm.Guest.IPAddress | ForEach-Object {
$obj.Add("IP$($i)", $_)
$i++
}
New-Object PSObject -Property $obj
}
$report | Sort-Object -Property { ($_ | Get-Member -MemberType Properties).Count } -Descending |
Export-Csv C:\Users\gemela\Desktop\machine_ip.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That is awesome. I was looking all over for those 2 commands. Is it possible for guest name to be the FQDN?
Sure, try like this
$report = foreach ($vm in Get-VM) {
$obj = [ordered]@{
Name = $vm.Name
FQDN = $vm.Guest.HostName
PowerState = $vm.PowerState
GuestOS = $vm.Guest.OSFullname
}
$i = 1
$vm.Guest.IPAddress | ForEach-Object {
$obj.Add("IP$($i)", $_)
$i++
}
New-Object PSObject -Property $obj
}
$report | Sort-Object -Property { ($_ | Get-Member -MemberType Properties).Count } -Descending |
Export-Csv C:\Users\gemela\Desktop\machine_ip.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you Very much!!
hi @LucD
I tried:
Get-VM | Select Name, @{N="IP Address";E={@($_.guest.IPAddress[0])}}and all other programs given below but none seems to be working, probably because Guest field is empty for my VM output.
I have to take these files and further I can export them to csv. Exporting to CSV, I know how it's done but all these vm files I am getting only name but No IP Address.
Sample Output or Get-Vm | Format-List in Powershell ISE
Name : VM_5360
PowerState : PoweredOn
Notes :
Guest :
NumCpu : 1
CoresPerSocket : 1
MemoryMB : 4096
MemoryGB : 4
VMHostId :
VMHost :
VApp :
FolderId :
Folder :
ResourcePoolId :
ResourcePool :
HARestartPriority : ClusterRestartPriority
HAIsolationResponse : AsSpecifiedByCluster
DrsAutomationLevel : AsSpecifiedByCluster
VMSwapfilePolicy :
VMResourceConfiguration : CpuShares:Normal/1000 MemShares:Normal/40960
Version :
PersistentId :
GuestId :
UsedSpaceGB :
ProvisionedSpaceGB :
DatastoreIdList :
ExtensionData : VMware.Vim.VirtualMachine
CustomFields : {}
Id : VirtualMachine-vm-1893
Uid : /VIServer=vsphere.local\administrator@100.100.10.97:443/VirtualMachine=VirtualMachine-vm-1893/
Powershell Version:
PS C:\Users\Administrator> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.20348.1366
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.20348.1366
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
And PowerCLI version:
PS C:\Users\Administrator> gET-pOWERclivERSION
WARNING: The cmdlet "Get-PowerCLIVersion" is deprecated. Please use the 'Get-Module' cmdlet instead.
PowerCLI Version
----------------
VMware PowerCLI 10.0.0 build 7895300
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component PowerCLI Component 10.0 build 7893915
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 10.0 build 7893909
PS C:\Users\Administrator> $Global:DefaultVIServers | select Name, Version, Build
Name Version Build
---- ------- -----
100.100.10.97 8.0.1 21201873
ESXi Being Used on which VM are hosted: 7.0.3 (1e)
If the VMware Tools are not installed there will be no info under the Guest property.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks @LucD ,
I updated VmWareTools and it now works fine for me now. ![]()
Keep shining ![]()
