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
You can join the elements of the array together in one string.
Like this
Get-VM |
Select Name,VMHost, @{N="IP Address";E={@($_.guest.IPAddress -join '|')}} |
Export-Csv -NoTypeInformation C:\Users\gemela\Desktop\machine_ip.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can join the elements of the array together in one string.
Like this
Get-VM |
Select Name,VMHost, @{N="IP Address";E={@($_.guest.IPAddress -join '|')}} |
Export-Csv -NoTypeInformation C:\Users\gemela\Desktop\machine_ip.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot LucD
Hi LucD
With this script I got all IP for each VM,
But when generating csv all of them are in one line (separated with pipe)
Is possible to configure the script to get 3 different column?
Thanks
Try something like this
$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 C:\Users\gemela\Desktop\machine_ip.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This give me only an empty column, no result.
There were some typos in there, I corrected the code above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi
Can you also suggest getting all IPs in separate rows and not columns? If a server has 3 IPs, I will ike to see a report with 3 rows and not 3 columns.
Thanks!
Sure, try like this
$report = foreach($vm in Get-VM){
foreach($ip in $vm.Guest.IPAddress){
$obj = [ordered]@{
Name = $vm.Name
Host = $vm.VMHost.Name
IP = $ip
}
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
@LucD - very helpful! Thanks!
Add a property with the result of the Get-TagAssignment cmdlet.
Note that this property will be repeated for each IP address
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am using the script below, where do I add the Get-Assignment for tag Category Backup, for example?
Get-VM |
Select Name,VMHost, @{N="IP Address";E={@($_.guest.IPAddress -join '|')}} |
Export-Csv -NoTypeInformation C:\Users\gemela\Desktop\machine_ip.csv
You could do something like this
Select Name,VMHost,
@{N="IP Address";E={@($_.guest.IPAddress -join '|')}},
@{N='Tag';E={(Get-TagAssignment -Entity $_ -Category 'Backup').Tag.Name}} |
Export-Csv -NoTypeInformation C:\Users\gemela\Desktop\machine_ip.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Exactly what I needed, thanks LucD@
You could do something like this
$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
Absolutely brilliant, thank you!
Hi.
Thank you for your code. It works like a charm. I was wondering if you can try to convert it from the "Get-VM" cmdlet to "Get-View". I was trying but I got stuck at some point.
Thank you in advance for your suggestions.
Hernan
Is it possible to get MAC address too with IP details here?
Thank you