Hi,
Need a powershell script to collect the below given info from virtual center.
vmname | ESX Name | memory(GB) | vCPU count | vNIC Count | IP address(all) | vmdk(s) size(GB) | Total vmdk size(GB) | Datastore name | Tools version | tools update | shares | reservations(MB) | limit(MB) | snapshot count | Guest OS
vmdk(s) size(GB) ---> Need all vmdk size of the vm seperated by "". EX: for a vm of 3 vmdk's of size 20,20,10GB each the output would be 2020+10
Datastore Name ---> Name of the datastore where VMX is located.
Tools update ---> Need status like old or updated
Nothing specific, just wanted it to be in html and send to email.
Thanks LucD
Hi Luc,
There are almost 3500+ VMs in our environment and its taking more than 10hours to complete this script. Is there any tweaks that can be made to have it completed in less amount of time. Also this is used on a daily basis.
There are a couple of tricks to make scripts faster in bigger environments.
Do you mean the script from this thread ? And if yes, which variation (there are quite a few).
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes... the script from your comment in #59
$allLines = @() # Line added
$null | Out-File "C:\vmnotfound.txt"
Get-Content -Path "C:\vmnames.txt" | %{ $vm = Get-VM -Name $_ -ErrorAction SilentlyContinue
if(!$vm){ $_ | Out-File "C:\vmnotfound.txt" -Append } else{ $VMResourceConfiguration = $VM | Get-VMResourceConfiguration
$VMHardDisks = $VM | Get-HardDisk
$HardDisksSizesGB = @() $Temp = $VMHardDisks | ForEach-Object { $HardDisksSizesGB += [Math]::Round($_.CapacityKB/1MB) } $VmdkSizeGB = ""
$Temp = $HardDisksSizesGB | ForEach-Object { $VmdkSizeGB += "$_+" } $VmdkSizeGB = $VmdkSizeGB.TrimEnd("+") $TotalHardDisksSizeGB = 0
$Temp = $HardDisksSizesGB | ForEach-Object { $TotalHardDisksSizeGB += $_ } $VMDKnames = @() $Temp = $VMHardDisks | ForEach-Object { $VMDKnames += $_.Filename.Split("/")[1] } $Snapshots = $VM | Get-Snapshot
$Report = "" | Select-Object VMname,vmCreatedByUser,vmCreatedDate,ESXname,ClusterName,MemoryGB,vCPUcount,vNICcount,vNICType, IPaddresses,VMXname,VMDKname,VmdkSizeGB,TotalVmdkSizeGB,DatastoreName,ToolsVersion,ToolsUpdate,NumCpuShares, CpuLimitMHZ,CpuReservationMHZ,NumMemShares,ReservationsMB,LimitMB,SnapshotCount,GuestOS,VLANid,Portgroup, RDMPath $Report.VMName = $VM.name $Report.vmCreatedByUser = $VM.CustomFields["CreatedBy"] $Report.vmCreatedDate = $VM.CustomFields["CreatedOn"] $Report.ESXname = $VM.Host $Report.ClusterName = ($VM | Get-Cluster).Name $Report.MemoryGB = $VM.MemoryMB/1KB $Report.vCPUcount = $VM.NumCpu $Report.vNICcount = $VM.Guest.Nics.Count $report.vNicType = [string]::Join(',',($vm.NetworkAdapters | %{$_.Type})) $Report.IPaddresses = [string]::Join(',',$VM.Guest.IPAddress) $Report.VMXname = $vm.Extensiondata.Config.Files.VmPathName.Split("/")[1] $Report.VMDKname = [string]::Join(',',$VMDKnames) $Report.VmdkSizeGB = $VmdkSizeGB
$Report.TotalVmdkSizeGB = $TotalHardDisksSizeGB
$Report.DatastoreName = [string]::Join(',',($vm.Extensiondata.Config.DatastoreUrl | %{$_.Name})) $Report.ToolsVersion = $vm.Extensiondata.Config.Tools.ToolsVersion $Report.ToolsUpdate = $vm.Extensiondata.Guest.ToolsStatus $Report.NumCpuShares = $VMResourceConfiguration.NumCPUShares $Report.CpuLimitMHZ = &{if($VMResourceConfiguration.CpuLimitMhz -eq -1){"No Limit"}else{$VMResourceConfiguration.CpuLimitMhz}} $Report.CpuReservationMHZ = $VMResourceConfiguration.CpuReservationMhz $Report.NumMemShares = $VMResourceConfiguration.NumMemShares $Report.ReservationsMB = $VMResourceConfiguration.MemReservationMB $Report.LimitMB = &{if($VMResourceConfiguration.MemLimitMB -eq -1){"No Limit"}else{$VMResourceConfiguration.MemLimitMB}} $Report.SnapshotCount = (@($VM | Get-Snapshot)).Count $Report.GuestOS = $VM.Guest.OSFullName $Report.VLANid = [string]::Join(',',(Get-VirtualPortgroup -VM $vm | %{$_.VlanId})) $Report.Portgroup = [string]::Join(',',(Get-VirtualPortgroup -VM $vm | %{$_.Name})) $RDMPaths = $vm | Get-HardDisk | where {$_.DiskType -like "Raw*"} $Report.RDMPath = &{if($RDMPaths){[string]::Join(',',($RDMPaths | %{$_.ScsiCanonicalName}))}else{"No RDM"} } $allLines += $Report # Line changed } } $allLines | Export-Csv "C:\VMreport.csv" -NoTypeInformation -UseCulture
Hi Luc,
Any updates ?
Hi Robert,
is it possible to add Custom Attributes to the list? I am able to add Notes by adding $Report.Note = $VM.Notes and also added "Notes" to the Select-Object line, but to no avail to get any Custom Attributes to be displayed. Thank you.