Use Pester to Mock "Dummy Computers" for testing Get-WMIObject Queries

Hello,

I’m working on some operational tests for Group Policy WMI Filters. What I want to accomplish is pulling all WMI Filters from Active Directory (accomplished with https://gallery.technet.microsoft.com/scriptcenter/Group-Policy-WMI-filter-38a188f3) and loop thru them testing the query of each one against multiple operating systems or system types.

The issue I’m having is that it (appears) I can only mock the output of the call, but what I need to do is mock the INPUT. Meaning, I want to mock the Win32_OperatingSystem Class of a Windows 7 system, a Windows 8.1 system AND a Windows 10 system and execute the WMI Query against each mock to see how it behaves. I know I can do this by connecting to LIVE systems, but I’m hoping I can avoid that so I don’t need to find or build a live system each time I want to test this.

I’ve created a gist with my code thus far: Test Group Policy WMI Filters with Pester · GitHub

I don’t think what you are asking is possible. From my understanding, you’re wanting to query a WMI repository without actually touching one. There’s no way to mock what that WMI repo would return. You can only mock what a command returns. I suggest you collect a bunch of workstations and perform the actual query with PowerShell. If you do the actual query, you can then use Pester to validate those machines are returning what you’d expect.