Is it possible to delete a WMI/CIM class using the Microsoft.Management.Infrastructure?

Francisco Nabas 31 Reputation points
2023-05-31T22:22:40.65+00:00

Every time I write a script, or code that uses WMI extensively, I tend to use the System.Management API. It's straight forward, flexible, and intuitive.
However, This time I decided to use the Microsoft.Management.Infrastructure API, which contains the famous CimCmdlets.
Part of my script needs to delete a CIM Class, but I can't find how, using only CIM.
I know there's the System.Management.ManagementClass.Delete() method, but can't seem to find something similar.
I tried Microsoft.Management.Infrastructure.CimSession.DeleteInstance(), but of course it doesn't work.

I am trying to delete the class itself, not the class instances.

Can't find documentation on it anywhere. Any ideas?

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,701 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,415 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,429 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,307 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,100 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 43,966 Reputation points
    2023-06-02T12:42:05.0566667+00:00

    Hello there,

    The Remove-DhcpServerv4PolicyIPRange cmdlet deletes an IP range from an existing policy at the scope level.

    If you specify neither the StartRange nor the EndRange parameter, all of the IP address ranges associated with the policy are deleted.

    If you specify only the StartRange parameter, the policy IP address range which has the specified starting address is deleted.

    If you specify only the EndRange parameter, the policy IP address range which has the specified ending address is deleted.

    https://learn.microsoft.com/en-gb/powershell/module/dhcpserver/remove-dhcpserverv4policyiprange?view=windowsserver2019-ps&wt.mc_id=ps-gethelp

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer–


  2. Rich Matheisen 45,096 Reputation points
    2023-06-02T15:24:29.93+00:00

    Have a look at this PowerShell module: https://www.powershellgallery.com/packages/pswmitoolkit/3.1.1

    It contains a function (usable only within the module) to remove a WMI class (https://www.powershellgallery.com/packages/pswmitoolkit/3.0.42/Content/Public%5CRemove-WmiClass.ps1)

    0 comments No comments