Hello guys,
i need help to extract from my VCenter, with powercli script , all information like this :
Name | State | Uptime | NIC | PortGroup |
| IP | Host | Provisioned Space | Used Space | CPU | RAM |
Reservation - RAM/CPU | VMDK / Datastore | Host CPU - MHz | Host Mem - MB | Notes | Fault Tolerance | Snapshot | VMWare Tools | NB_LAST_BACKUP | Tags |
and send email on cvs and html format.
Please help me.
Thx
Davide
Davide Owner
i remove the loop
Can you try like this, without changing or adding anything?
I updated the calculation for the Owner tag.
$report = @()
foreach($vm in Get-View -ViewType Virtualmachine){
$vms = "" | Select-Object VMName, Hostname, IPAddress, OS, Boottime, VMState, TotalCPU, CPUAffinity,
CPUHotAdd, CPUShare, CPUlimit, OverallCpuUsage, CPUreservation, TotalMemory, MemoryShare, MemoryUsage,
MemoryHotAdd, MemoryLimit, MemoryReservation, Swapped, Ballooned, Compressed, TotalNics, ToolsStatus,
ToolsVersion, HardwareVersion, TimeSync, CBT, Portgroup, VMHost, ProvisionedSpaceGB, UsedSpaceGB, Datastore,
Notes, FaultTolerance, SnapshotName, SnapshotDate, SnapshotSizeGB, Owner, NB_last_backup
$vms.VMName = $vm.Name
$vms.Hostname = $vm.guest.hostname
$vms.IPAddress = $vm.guest.ipAddress
$vms.OS = $vm.Config.GuestFullName
$vms.Boottime = $vm.Runtime.BootTime
$vms.VMState = $vm.summary.runtime.powerState
$vms.TotalCPU = $vm.summary.config.numcpu
$vms.CPUAffinity = $vm.Config.CpuAffinity
$vms.CPUHotAdd = $vm.Config.CpuHotAddEnabled
$vms.CPUShare = $vm.Config.CpuAllocation.Shares.Level
$vms.TotalMemory = $vm.summary.config.memorysizemb
$vms.MemoryHotAdd = $vm.Config.MemoryHotAddEnabled
$vms.MemoryShare = $vm.Config.MemoryAllocation.Shares.Level
$vms.TotalNics = $vm.summary.config.numEthernetCards
$vms.OverallCpuUsage = $vm.summary.quickStats.OverallCpuUsage
$vms.MemoryUsage = $vm.summary.quickStats.guestMemoryUsage
$vms.ToolsStatus = $vm.guest.toolsstatus
$vms.ToolsVersion = $vm.config.tools.toolsversion
$vms.TimeSync = $vm.Config.Tools.SyncTimeWithHost
$vms.HardwareVersion = $vm.config.Version
$vms.MemoryLimit = $vm.resourceconfig.memoryallocation.limit
$vms.MemoryReservation = $vm.resourceconfig.memoryallocation.reservation
$vms.CPUreservation = $vm.resourceconfig.cpuallocation.reservation
$vms.CPUlimit = $vm.resourceconfig.cpuallocation.limit
$vms.CBT = $vm.Config.ChangeTrackingEnabled
$vms.Swapped = $vm.Summary.QuickStats.SwappedMemory
$vms.Ballooned = $vm.Summary.QuickStats.BalloonedMemory
$vms.Compressed = $vm.Summary.QuickStats.CompressedMemory
$vms.Portgroup = Get-View -Id $vm.Network -Property Name | select -ExpandProperty Name
$vms.VMHost = Get-View -Id $vm.Runtime.Host -property Name | select -ExpandProperty Name
$vms.ProvisionedSpaceGB = [math]::Round(($vm.Summary.Storage.Committed + $vm.Summary.Storage.UnCommitted)/1GB,2)
$vms.UsedSpaceGB = [math]::Round($vm.Summary.Storage.Committed/1GB,2)
$vms.Datastore = $vm.Config.DatastoreUrl[0].Name
$vms.Notes = $vm.Config.Annotation
$vms.FaultTolerance = $vm.Runtime.FaultToleranceState
$vms.SnapshotName = &{$script:snaps = Get-Snapshot -VM $vm.Name; $script:snaps.Name -join ','}
$vms.SnapshotDate = $script:snaps.Created -join ','
$vms.SnapshotSizeGB = $script:snaps.SizeGB -join ','
$vms.Owner = (Get-TagAssignment -Category Owner -Entity $vm.Name).Tag.Name
$vms.NB_last_backup = Get-VM -Name $vm.Name | select -ExpandProperty Customfields | where{$_.Key -eq 'Last Backup'} | select -ExpandProperty Value
$Report += $vms
}
$report
Updated the ProvisionedSpaceGB property.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
not function
I think the script can not find some field
i start without any modification
If the script can't find some fields, there should be error messages.
You made sure you are connected to a vCenter (what is in $global:defaultviservers)?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Ok, and what about error messages?
And perhaps attach the actual script you are using as a file attachment.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc , no error messages, and this is the output for html
Function Create-HTMLTable
{
param([array]$Array)
$arrHTML = $Array | ConvertTo-Html
$arrHTML[-1] = $arrHTML[-1].ToString().Replace(‘</body></html>’,"")
Return $arrHTML[5..2000]
}
$output = @()
$output += ‘<html><head></head><body>’
$output +=
‘<style>table{border-style:solid;border-width:1px;font-size:8pt;background-color:#7ab0f9;width:100%;}th{text-align:left;}td{background-color:#fff;width:20%;border-style:so
lid;border-width:1px;}body{font-family:verdana;font-size:12pt;}h1{font-size:12pt;}h2{font-size:10pt;}</style>’
$output += ‘<H2>Date and time</H2>’,$date
the script has put us more than expected, but the Owner information is clear, and the storage fileds are empty, no data
Can we first check that the $report of the original script is producing output?
By adding stuff, like this HTML thing, trying to find a solution is becoming a moving target I'm afraid.
Let's first fix the simple ForEach loop before adding new features in the script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Luc i inform you that it works there was only more time. thanks for everything and wonderful info
You're welcome.
Yes, the Tag cmdlets are not the fastest I'm afraid.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You're welcome.
See you in Milan next month 🙂
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes.
But was is the appwiz.cpl remark?
Does that show another version?
And how would you select the servers?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hey
great script 🙂
how do i get multiple ip's if a vm has it? i tried to use -join etc on the line:-
$vms.IPAddress = $vm.guest.ipAddress
thanks in advance
mark
The following should work
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi, this still only brings back the 1 ip address unfortunately?
thanks
And you are sure that $vm.Guest.IPAddress contains multiple IP addresses?
Seems to work for me for all VMs that have more than connection.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hi Luc
yes they do and here is the interesting thing, when i run the script with:-
foreach($vm in Get-View -ViewType Virtualmachine )
it returns only 1 ip address as below:-
PS C:\Users\> $vm.Guest.IPAddress
192.xx.xx.xx
PS C:\Users\> $vms.IPAddress
192.xx.xx.xx
But when i run the script with this:-
foreach($vm in Get-vm -Name stg-ao-pcdr-01)
it returns all IP's:-
PS C:\Users\> $vm.Guest.IPAddress
192.xx.xx.xx
10.xx.xx.xx
10.xx.xx.xx
10.xx.xx.xx
10.xx.xx.xx
PS C:\Users\> $vms.IPAddress
192.xx.xx.xx,10.xx.xx.xx,10.xx.xx.xx,10.xx.xx.xx,10.xx.xx.xx
obviously the get-vm doesn't bring back all the info required though.