KB0066 - Get-WMIObject cmdlet not working

KB0066 - Get-WMIObject cmdlet not working

Scope

This article applies to any scenario where the Get-WMIObject cmdlet is expected to be available and functioning within a PowerShell Universal instance. Effectively, this article will only apply to instances that run under the Windows operating system.

Problem

Get-WMIObject is not recognized as a cmdlet within any of the PowerShell Universal script editing interface.


(figure shows a Script in PowerShell Universal is not recognizing the Get-WMIObject cmdlet)

Root Cause

PowerShell Universal, by default, uses the integrated PowerShell environment which will be a recent version of PowerShell Core (i.e. it is not Windows PowerShell). The Get-WMIObject cmdlet was deprecated in favor of Get-CimInstance in PowerShell Core therefore it only exists in legacy Windows PowerShell.

Solution #1 (Recommended)

Adapt your code to use Get-CimInstance instead of Get-WMIObject.



Solution #2

Change the Environment of the (script, app, endpoint) to use the Windows PowerShell environment instead of the default Integrated environment

Please read the documentation and be advised around the implications of using Windows PowerShell in your PowerShell Universal workloads[1]

 
(figure shows the Environment changed to Windows PowerShell on a PowerShell Universal Script)


(figure shows the results of Get-WMIObject when run through a Windows PowerShell environment)


Reference

    • Related Articles

    • PowerShell Universal Service crashes on startup after an upgrade to 1.4.6

      Version: PowerShell Universal 1.4.6 Issue The PowerShell Universal service will crash with the following error in Event Viewer.  Application: Universal.Server.exe CoreCLR Version: 4.700.19.56402 .NET Core Version: 3.1.0 Description: The process was ...
    • KB0036 - How to set the license via environment variable

      Purpose The purpose of this article is to explain how to set the license for PowerShell Universal by way of environment variable instead of the traditional file-based method. Scope For now, only Windows is in the scope of this article. Linux and ...
    • PowerShell Universal cmdlets return a 404 over HTTPS

      Version: 1.4 PowerShell Version: Windows PowerShell 5.1 Problem When issue commands against the PowerShell Universal Management API (such as Get-UAJob, Get-UAScript, etc), the cmdlet will return a 404 error. This can happen when running scripts ...
    • KB0017 - Windows Auth Checklist

      Purpose The purpose of this article is to list the prerequisite conditions for ensuring that Windows Authentication in PowerShell Universal will function as expected (i.e. seamless logon without authentication pop-ups) Scope The scope of this article ...
    • KB0035 - How to add the Calendar and other components

      Purpose The purpose of this article is to demonstrate how to install and use the Calendar component (module) Background There is a growing list of add-on components (modules) for PowerShell Universal at ...