I just want to leave this script here that maybe help others. Recently we have to retrieve all the NIC MAC Address from all our guest VM and their guest OS IP. To solve this tedious task I write this simple code that could evolve in something more robust if someone tweak the code.
As is the code retrieve the following from the VM:
VM UUID
VM Name
VM Description
# of CPU
Memory in Bytes
VM Power State
Is Template
NIC ID (The number of the NIC device)
Network Name (Attached to the NIC)
NIC MAC Address
NIC VLAN (From the Network Attached)
NIC IP (From the Guest OS)
I run this code on multiple XenServer 6.5 & 6.0 using the XenServer 6.5 SDK without issues. The only thing that I notice is that on XS6.0 the VLAN data can not be read. Also the XenTools must be installed to retrieve the OS IP address.
Any suggestions would be appreciated.
-----------Script Start------------------
Import-ModuleXenServerPSModule Connect-XenServer-Urlhttps://10.20.10.xx-UserNameserveruser-Passwordserverpassword $vms =get-xenvm|Where-Object{$_.is_a_template-ne"False"-and$_.is_control_domain-ne"False"}#get all vms
Question
Alvin Adorno
Greetings,
I just want to leave this script here that maybe help others. Recently we have to retrieve all the NIC MAC Address from all our guest VM and their guest OS IP. To solve this tedious task I write this simple code that could evolve in something more robust if someone tweak the code.
As is the code retrieve the following from the VM:
I run this code on multiple XenServer 6.5 & 6.0 using the XenServer 6.5 SDK without issues. The only thing that I notice is that on XS6.0 the VLAN data can not be read. Also the XenTools must be installed to retrieve the OS IP address.
Any suggestions would be appreciated.
-----------Script Start------------------
Import-Module XenServerPSModule
Connect-XenServer -Url https://10.20.10.xx -UserName serveruser -Password serverpassword
$vms = get-xenvm | Where-Object {$_.is_a_template -ne "False" -and $_.is_control_domain -ne "False"} #get all vms
function New-XenVMInfo
{
New-Object PSObject -Property @{
Name = ''
UUID = ''
CPUCount = ''
Description = ''
IsTemplate = ''
MemoryStaticMax =''
PowerState = ''
NICID = ''
NICNetworkName = ''
NICMAC = ''
NICVLAN = ''
NICIP = ''
}
}
$xenVMs = @()
foreach ($vm in $vms){
$gm = Get-XenVMProperty -VM $vm -XenProperty GuestMetrics
if ($vm.VIFs.Count -gt 1)
{
for ($i=0; $i -lt $vm.VIFs.Count;$i++)
{
$xenVM = New-XenVMInfo
$xenVM.Name = $vm.name_label
$xenVM.PowerState = $vm.power_state
$xenVM.UUID = $vm.uuid
$xenVM.Description = $vm.name_description
$xenVM.IsTemplate = $vm.is_a_template
$xenVM.MemoryStaticMax = $vm.memory_static_max
$xenVM.CPUCount = $vm.vcpus_max
$vif = Get-XenVIF -Ref $vm.VIFs[$i]
$net = Get-XenNetwork -Ref $vif.network
$xenVM.NICNetworkName = $net.name_label
$pif = Get-XenPIF -Ref $net.PIFs[0]
$xenVM.NICVLAN = $pif.VLAN
$xenVM.NICMAC = $vif.MAC
$xenVM.NICID = $vif.device
$xenVM.NICIP = ($gm.networks)[ $vif.device + "/ip"]
$xenVMs += $xenVM
}
}
elseif ($vm.VIFs.Count -eq 1)
{
$xenVM = New-XenVMInfo
$xenVM.Name = $vm.name_label
$xenVM.PowerState = $vm.power_state
$xenVM.UUID = $vm.uuid
$xenVM.Description = $vm.name_description
$xenVM.IsTemplate = $vm.is_a_template
$xenVM.MemoryStaticMax = $vm.memory_static_max
$xenVM.CPUCount = $vm.vcpus_max
$vif = Get-XenVIF -Ref $vm.VIFs[0]
$net = Get-XenNetwork -Ref $vif.network
$xenVM.NICNetworkName = $net.name_label
$pif = Get-XenPIF -Ref $net.PIFs[0]
$xenVM.NICVLAN = $pif.VLAN
$xenVM.NICMAC = $vif.MAC
$xenVM.NICID = $vif.device
$xenVM.NICIP = ($gm.networks)[ $vif.device + "/ip"]
$xenVMs += $xenVM
}
else
{
$xenVM = New-XenVMInfo
$xenVM.Name = $vm.name_label
$xenVM.PowerState = $vm.power_state
$xenVM.UUID = $vm.uuid
$xenVM.Description = $vm.name_description
$xenVM.IsTemplate = $vm.is_a_template
$xenVM.MemoryStaticMax = $vm.memory_static_max
$xenVM.CPUCount = $vm.vcpus_max
$xenVM.NICID = 'No NIC Attached'
$xenVM.NICNetworkName = 'No NIC Attached'
$xenVM.NICVLAN = 'No NIC Attached'
$xenVM.NICMAC = 'No NIC Attached'
$xenVM.NICIP = 'No IP Available'
$xenVMs += $xenVM
}
}
$xenVMs | Export-Csv -Path c:\NetworkInfo.csv
Disconnect-XenServer
Link to comment
2 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now