I am trying to run few commandlets and it is running very slow. i dont know, why this happens, OR this is a expected behaviour.
For ex - Get-VMResourceConfiguration vm-name
Will take a long time to execute.
The Snapins that are installed
PS C:\> Get-PSSnapin
Name : Microsoft.PowerShell.Diagnostics
PSVersion : 2.0
Description : This PS snap-in contains get-winevent cmdlet used to read Windows event log data and configuration.
Name : Microsoft.WSMan.Management
PSVersion : 2.0
Description : This Windows PowerShell snap-in contains cmdlets (such as Get-WSManInstance and Set-WSManInstance) that are used by the Window
s PowerShell host to manage WSMan operations.
Name : Microsoft.PowerShell.Core
PSVersion : 2.0
Description : This Windows PowerShell snap-in contains Windows PowerShell management cmdlets used to manage components of Windows PowerShell
.
Name : Microsoft.PowerShell.Utility
PSVersion : 2.0
Description : This Windows PowerShell snap-in contains utility Cmdlets used to manipulate data.
Name : Microsoft.PowerShell.Host
PSVersion : 2.0
Description : This Windows PowerShell snap-in contains cmdlets used by the Windows PowerShell host.
Name : Microsoft.PowerShell.Management
PSVersion : 2.0
Description : This Windows PowerShell snap-in contains management cmdlets used to manage Windows components.
Name : Microsoft.PowerShell.Security
PSVersion : 2.0
Description : This Windows PowerShell snap-in contains cmdlets to manage Windows PowerShell security.
Name : VMware.VimAutomation.Core
PSVersion : 2.0
Description : This Windows PowerShell snap-in contains Windows PowerShell cmdlets used to manage VMware Infrastructure.
PS C:\>
To be fair Get-VMResourceConfiguration is doing alot of work to display all of a vm's resources in one object, but I too have found it to be painfully slow at times.
If you know exactly what metrics your most interested in then it's possible to significantly increase script performance. For example, I use this filter to check for any misconfigured RAM/CPU allocations once a week.
Filter Get-VMLimits { $_| Get-View -Property ResourceConfig,Name | Tee-Object -Variable VirtualMachine | select-object -ExpandProperty ResourceConfig | select-Object @{ Name = 'Name' Expression = {$VirtualMachine.Name} }, @{ Name = 'NumCpuShares' Expression = {$_.CpuAllocation.Shares.Shares} }, @{ Name= 'CpuReservationMhz' Expression = {$_.CpuAllocation.Reservation} }, @{ Name= 'CpuLimitMhz' Expression = {$_.CpuAllocation.Limit} }, @{ Name= 'CpuSharesLevel' Expression = {$_.CpuAllocation.Shares.Level} }, @{ Name= 'NumMemShares' Expression = {$_.memoryallocation.Shares.Shares} }, @{ Name= 'MemReservationMB' Expression = {$_.memoryallocation.Reservation} }, @{ Name= 'MemLimitMB' Expression = {$_.memoryallocation.Limit} }, @{ Name= 'MemSharesLevel' Expression = {$_.memoryallocation.Shares.Level} } } get-vm| Get-VMLimits
By limiting the scope to just the resourceconfiguration, you can really make the toolkit perform. Again though this performance comes from our ability to limit the scope and only retrieve the data we need. If I were to write a function that retrieved everything Get-VMResourceConfiguration does, and performed the same number of checks it would take twice as long. Long story short if you can live with the performance, then the native cmdlets are the safest/easiest route. If you can't the only real alternative is to get friendly with get-view and the VI object model.
~Glenn
The reason is the same reason described in this blog post.
To work around this, do something like this:
$vm = Get-View -ViewType VirtualMachine -Filter @{"Name" = "vm-name"} | Get-VIObjectByVIView Get-VMResourceConfiguration $vm
This should be a considerable amount faster. Some people have reported that this doesn't work for them, so if you're one of them please say so.