fix: replace Get-WmiObject with Get-CimInstance in UWF query (RULE-1)#5
fix: replace Get-WmiObject with Get-CimInstance in UWF query (RULE-1)#5dutch2005 wants to merge 1 commit into
Conversation
`Get-WmiObject` was removed from PowerShell 7. The cmdlet does not exist in the 7.4+ runtime this module targets, so the Unified Write Filter branch of Get-DeviceComplianceStatus would throw `CommandNotFoundException` the moment an Enterprise SKU reached that code path. CIM is the supported replacement: same namespace, same class, same behavior. Parameter name changes from `-Class` to `-ClassName`. No other call sites use `Get-WmiObject` anywhere in Private/. This is also explicitly forbidden by lazywinadmin.speq CONTRACT CIM-ONLY and the Gemini / CodeRabbit style guides. Ref: code-review-2026-04-24.md — RULE-1 (CRITICAL).
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 57 minutes and 31 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (1 files)
Reviewed by nemotron-3-super-120b-a12b-20230311:free · 116,768 tokens |
There was a problem hiding this comment.
Code Review
This pull request updates the Get-DeviceComplianceStatus script by replacing the deprecated Get-WmiObject cmdlet with Get-CimInstance. A review comment points out that if the CIM query returns no results, subsequent property access on the null variable will trigger a PropertyNotFoundException due to the module's strict mode settings. It is recommended to use the null-coalescing operator to provide a default object and prevent script failure.
| $feature = Get-WindowsOptionalFeature -Online -FeatureName 'Client-UnifiedWriteFilter' -ErrorAction SilentlyContinue | ||
| if ($feature.State -eq 'Enabled') { | ||
| $uwf = Get-WmiObject -Namespace 'root\standardcimv2\embedded' -Class 'UWF_Filter' -ErrorAction SilentlyContinue | ||
| $uwf = Get-CimInstance -Namespace 'root\standardcimv2\embedded' -ClassName 'UWF_Filter' -ErrorAction SilentlyContinue |
There was a problem hiding this comment.
Since the module enables Set-StrictMode -Version Latest (configured in LazyWinAdminModule.psm1), accessing properties on a null variable will throw a PropertyNotFoundException. If Get-CimInstance returns no instances (which can occur if the UWF filter is not yet initialized or in certain transient error states), $uwf will be $null, causing the script to fail on lines 87 and 88.
Since this module targets PowerShell 7.4, you can use the null-coalescing operator (??) to provide a safe default object. This ensures that $status and $detail are populated correctly even if the WMI query returns no results, avoiding an unnecessary exception that would otherwise be caught by the generic try/catch block.
$uwf = (Get-CimInstance -Namespace 'root\standardcimv2\embedded' -ClassName 'UWF_Filter' -ErrorAction SilentlyContinue | Select-Object -First 1) ?? [PSCustomObject]@{ CurrentEnabled = $false }
Summary
Get-WmiObjectwas removed from PowerShell 7. The cmdlet does not exist in the 7.4+ runtime this module targets, so the Unified Write Filter branch ofGet-DeviceComplianceStatuswould throwCommandNotFoundExceptionthe moment an Enterprise SKU reached that code path. Swaps the single offending line forGet-CimInstance.Changes
LazyWinAdminModule/Private/Get-DeviceComplianceStatus.ps1:86—Get-WmiObject -Namespace ... -Class ...→Get-CimInstance -Namespace ... -ClassName ....Verified no other
Get-WmiObjectcall sites exist inLazyWinAdminModule/Private/.Test plan
LazyWinAdminModule/Tests/Run-Tests.ps1— full suite passes onwindows-latestRisks / rollback
Low risk.
Get-CimInstanceagainst theUWF_Filterclass is API-compatible for the one property read (CurrentEnabled). Rollback:git revert..speq compliance
Get-WmiObjectin Private/).CimSessionconventions (none needed here — no session, one-shot call).AI review
@gemini-code-assist please review
@coderabbitai review
@Kilo review
Related
code-review-2026-04-24.md— RULE-1 (CRITICAL)