Replace WMIC with powershell cmd
From Win11-24H2, WMIC is an optional feature for Windows, And it will be fully removed in the future.So replace the related cmd
ID: 3268
Summary by CodeRabbit
-
Bug Fixes
- Replaced deprecated Windows
wmiccommands with modern PowerShell alternatives for disk, memory, network, and file operations, improving compatibility and reliability. - Updated logic for retrieving and parsing Windows system information, including disk size, free disk space, memory, and network attributes.
- Improved file path detection and drive letter matching on Windows guests.
- Enhanced handling of wildcards when identifying virtio-win drive letters.
- Replaced deprecated Windows
-
Documentation
- Updated docstrings and comments to reflect the use of PowerShell commands instead of
wmic.
- Updated docstrings and comments to reflect the use of PowerShell commands instead of
-
Chores
- Added "powershell" and "CimInstance" to the list of ignored spell-check terms.
Hi @xiagao @heywji Would you please help test this MR with our acceptance test, thanks.
Test 271 acceptance with win2022,win11,win1032 and win2016 guests, this patch worked.
Hi @XueqiangWei @nanliu-r @fbq815 Would you please help test this MR, it is mainly for wmic repalcement.Thanks.
Acceptance test looks good. LGTM.
balloon_hotplug test cases now passed in Win2025
(1/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.q35: STARTED
(1/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.q35: PASS (50028.55 s)
(2/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_reboot.q35: STARTED
(2/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_reboot.q35: PASS (939.88 s)
(3/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_system_reset.q35: STARTED
(3/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_system_reset.q35: PASS (871.67 s)
(4/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_shutdown_after_unplug.q35: STARTED
(4/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_shutdown_after_unplug.q35: PASS (497.14 s)
(5/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_shutdown_after_plug.q35: STARTED
(5/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_shutdown_after_plug.q35: PASS (473.43 s)
(6/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_migrate.migrate_after_hotplug.q35: STARTED
(6/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_migrate.migrate_after_hotplug.q35: PASS (601.20 s)
(7/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_migrate.migrate_after_unplug.q35: STARTED
(7/7) Host_RHEL.m9.u6.ovmf.qcow2.virtio_scsi.up.virtio_net.Guest.Win2025.x86_64.io-github-autotest-qemu.balloon_hotplug.with_migrate.migrate_after_unplug.q35: PASS (694.86 s)
RESULTS : PASS 7 | ERROR 0 | FAIL 0 | SKIP 0 | WARN 0 | INTERRUPT 0 | CANCEL 0
Hi @yanan-fu @YongxueHong Would you please help review this MR?Thanks.
Hello @leidwang is there any plan to update this patch ? I am still hitting wmic command issues in Win11 recent test runs :confused:
Hello @leidwang is there any plan to update this patch ? I am still hitting wmic command issues in Win11 recent test runs 😕
Hi @mcasquer I will update this MR recently, sorry for the delay.Currently, if you hit the issue that wmic not installed, you can try to run unattended_install test case again, it should be helpful.
Just want to explain more about why we will hit this issue. Win11-24H2 and Win2025 remove wmic, and does not provide installer for wmic, so we have to install it from MSFT, which then requires downloading something from the MSFT server,, so the wmic installation sometimes fails.
Hello @leidwang is there any plan to update this patch ? I am still hitting wmic command issues in Win11 recent test runs 😕
Hi @mcasquer I will update this MR recently, sorry for the delay.Currently, if you hit the issue that wmic not installed, you can try to run unattended_install test case again, it should be helpful.
Just want to explain more about why we will hit this issue. Win11-24H2 and Win2025 remove wmic, and does not provide installer for wmic, so we have to install it from MSFT, which then requires downloading something from the MSFT server,, so the wmic installation sometimes fails.
@leidwang ok, I get the idea, but if I trigger an automated test loop I cannot run the unattended_install twice, which significantly affects automation purpose...
Hello @leidwang is there any plan to update this patch ? I am still hitting wmic command issues in Win11 recent test runs 😕
Hi @mcasquer I will update this MR recently, sorry for the delay.Currently, if you hit the issue that wmic not installed, you can try to run unattended_install test case again, it should be helpful. Just want to explain more about why we will hit this issue. Win11-24H2 and Win2025 remove wmic, and does not provide installer for wmic, so we have to install it from MSFT, which then requires downloading something from the MSFT server,, so the wmic installation sometimes fails.
@leidwang ok, I get the idea, but if I trigger an automated test loop I cannot run the unattended_install twice, which significantly affects automation purpose...
Yes, we have to replace all wmic related command in our framework and test cases, then this issue can be fully fixed.
Tested with vTPM test cases. LGTM
📝 Walkthrough
Walkthrough
This change set migrates all Windows system information and management commands in the codebase from the deprecated wmic utility to modern PowerShell commands using Get-CimInstance and related cmdlets. Updates span disk, memory, network, and file system utilities, with corresponding adjustments to output parsing and documentation. No public API signatures are changed.
Changes
| Cohort / File(s) | Change Summary |
|---|---|
Spell Ignore List Updatespell.ignore |
Added "powershell" and "CimInstance" to the spell checker ignore list. |
Disk Utilities: PowerShell Migrationvirttest/utils_disk.py |
Replaced Windows disk size retrieval command from wmic to PowerShell Get-CimInstance in get_disk_size_windows. |
Misc Utilities: PowerShell Migrationvirttest/utils_misc.py |
Updated Windows commands in get_free_disk, get_free_mem, and get_win_disk_vol from wmic to PowerShell equivalents. Adjusted docstrings to reflect PowerShell usage and parsing logic for condition strings. |
Network Utilities: PowerShell Migration & Helper Additionvirttest/utils_net.py |
Converted all Windows network interface and IP configuration commands from wmic to PowerShell. Added subnet_mask_to_prefix_length helper. Updated output parsing and documentation for affected functions. |
Netperf Utility: PowerShell Migrationvirttest/utils_netperf.py |
Changed process check command in Netperf.is_target_running from wmic to PowerShell Get-CimInstance. |
Windows File Path Utility: PowerShell Migrationvirttest/utils_test/__init__.py |
Updated get_windows_file_abs_path to use a PowerShell recursive file search instead of wmic datafile. Adjusted regex parsing for new output format. |
QEMU Test Utilities: PowerShell Migrationvirttest/utils_test/qemu/__init__.py |
Modified Windows memory size retrieval in MemoryBaseTest.get_guest_total_mem from wmic to PowerShell Get-CimInstance. |
Windows Drive Utilities: PowerShell Migration & Parsing Refactorvirttest/utils_windows/drive.py |
Replaced all wmic usage with PowerShell Get-CimInstance queries. Refactored property and condition parsing logic for disk and drive queries. Removed dependencies on wmic and utils_misc. |
Windows System Info Utility: PowerShell Migration & Parsing Refactorvirttest/utils_windows/system.py |
Replaced WMIC-based OS info retrieval with PowerShell Get-CimInstance in _osinfo. Refactored output parsing and removed wmic import. |
Virtio Win Drive Letter Utility: Wildcard Changevirttest/utils_windows/virtio_win.py |
Changed drive letter pattern from "virtio-win%" to "virtio-win*" in drive_letter_iso to align with PowerShell wildcard usage. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
-
Complexity: The migration from
wmicto PowerShell affects core logic in multiple modules, requires careful review of command syntax, output parsing, and error handling, and introduces new helper functions and docstring updates. - Scope: Changes span disk, memory, network, file, and system utilities, with several refactored parsing routines and removal of legacy dependencies.
- Estimated review time: Approximately 45 minutes for a thorough review, focusing on correctness of command replacements, output parsing, and backward compatibility.
[!NOTE]
⚡️ Unit Test Generation is now available in beta!
Learn more here, or try it out under "Finishing Touches" below.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Explain this complex logic. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai explain this code block. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and explain its main purpose. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
@leidwang I've check the code, seems this is windows only, please double confirm that, if it's true you could ignore me with this patch