Add CIM-based Get-SdnVMCim and Get-SdnVMNetworkAdapterCim for faster VM enumeration#605
Draft
arudell wants to merge 7 commits into
Draft
Add CIM-based Get-SdnVMCim and Get-SdnVMNetworkAdapterCim for faster VM enumeration#605arudell wants to merge 7 commits into
arudell wants to merge 7 commits into
Conversation
…VM enumeration Introduces two new functions that use direct CIM/WMI queries against the root/virtualization/v2 namespace instead of Get-VM and Get-VMNetworkAdapter cmdlets. This provides significantly faster performance on hosts with large numbers of VMs where the Hyper-V cmdlets often timeout. - Get-SdnVMCim: Retrieves VMs with state, health, and network adapter info - Get-SdnVMNetworkAdapterCim: Retrieves VM NICs (synthetic + emulated) Both functions support -ComputerName and -Credential for remote execution, and -VMName/-MacAddress filtering. The original Get-SdnVMNetworkAdapter is preserved for backward compatibility. Closes microsoft#404 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0881b5f1-0c2d-470d-ab0c-6da9f8744d9b
Replace Get-VM and Get-VMNetworkAdapter calls in Get-ServerConfigState with the new Get-SdnVMCim and Get-SdnVMNetworkAdapterCim functions. This avoids the slow Hyper-V cmdlet overhead when collecting config state on hosts with many VMs. The management OS adapter collection now also uses the CIM path, removing the need for individual Get-VMNetworkAdapterIsolation, TeamMapping, VLAN, and RoutingDomainMapping calls that each re-enumerate all adapters. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 220ab25a-0e38-4217-8e3c-e0a2e22fd7d9
- Get-SdnVMNetworkAdapterPortProfile now uses Get-SdnVMNetworkAdapterCim and queries Msvm_EthernetSwitchPortSecuritySettingData directly instead of calling Get-VMSwitchExtensionPortFeature per adapter. - Set-SdnVMNetworkAdapterPortProfile uses CIM to locate adapters and update existing port security settings via Set-CimInstance. Falls back to Hyper-V cmdlets only for initial port profile creation. This eliminates the per-adapter Get-VMSwitchExtensionPortFeature and Get-VMSwitchExtensionPortData calls that compound the enumeration overhead on hosts with many VMs. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 220ab25a-0e38-4217-8e3c-e0a2e22fd7d9
Resolve the virtual switch name by querying Msvm_VirtualEthernetSwitch and Msvm_EthernetPortAllocationSettingData. The port allocation's Parent property links to the adapter and HostResource links to the switch, allowing us to build a lookup table for both VM and ManagementOS adapters. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 220ab25a-0e38-4217-8e3c-e0a2e22fd7d9
Add a dedicated Get-SdnVMSwitchCim function that queries Msvm_VirtualEthernetSwitch and returns switch name, GUID, and metadata. Supports -Name filtering, -ComputerName/-Credential for remote access, and -CimSession for reusing an existing session. Update Get-SdnVMNetworkAdapterCim to call Get-SdnVMSwitchCim for the switch name lookup instead of querying the CIM class directly. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 220ab25a-0e38-4217-8e3c-e0a2e22fd7d9
…mSession Add New-SdnCimSession and Remove-SdnCimSession to SdnDiag.Utilities.psm1, mirroring the existing PSRemotingSession pattern. Sessions are named SdnDiag-Cim-* and reused when TestConnection() passes. Update Get-SdnVMSwitchCim, Get-SdnVMNetworkAdapterCim, and Get-SdnVMCim to use the centralized session management instead of inline New-CimSession calls. Remove per-function finally cleanup blocks since sessions are now managed centrally via Remove-SdnCimSession. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 220ab25a-0e38-4217-8e3c-e0a2e22fd7d9
When -All is specified, the function returns both VM network adapters and Management OS adapters together, matching the behavior of Get-VMNetworkAdapter -All. This fixes the bound parameter error when Get-SdnVMNetworkAdapterPortProfile -All passes through to the CIM function. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 220ab25a-0e38-4217-8e3c-e0a2e22fd7d9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces two new functions that use direct CIM/WMI queries against the
root/virtualization/v2namespace instead ofGet-VMandGet-VMNetworkAdaptercmdlets. This provides significantly faster performance on hosts with large numbers of VMs where the Hyper-V cmdlets often timeout.Changes
Msvm_ComputerSystemMsvm_SyntheticEthernetPortSettingDataBoth functions support
-ComputerNameand-Credentialfor remote execution, and-VMName/-MacAddressfiltering. The originalGet-SdnVMNetworkAdapteris preserved for backward compatibility.Why CIM over Hyper-V cmdlets
The
Get-VMandGet-VMNetworkAdaptercmdlets internally perform extensive object hydration and property enumeration that is unnecessary for diagnostics scenarios. Direct CIM queries return the needed data with minimal overhead, avoiding timeout exceptions on heavily loaded hosts.Closes #404