liveBook · Manning

Invoke-CimMethod

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

Invoke-CimMethod is a PowerShell cmdlet that invokes a method on one or more CIM objects.

Invoke-CimMethod invokes a method attached to one or more CIM objects. Unlike a PowerShell cmdlet, an object method cannot receive piped objects directly; this generic cmdlet bridges that gap. section 15.2

Enable DHCP on matching adapters

Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter "description like '%intel%'" | Invoke-CimMethod -MethodName EnableDHCP The method name needs no parentheses and is not case sensitive. section 15.2

Keep these constraints in mind:

  • Pass objects of only one CIM type, although multiple objects of that type are supported. section 15.2
  • Use -WhatIf and -Confirm for safer execution. section 15.2
  • Read ReturnValue to determine the operation result; 0 means success, while 84 means DHCP cannot be enabled on that adapter. section 15.2

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains discovery, invocation constraints, safety switches, and return values, but does not detail method implementation internals.
Examples
Uses Win32_NetworkAdapterConfiguration objects and the EnableDHCP method, including return values 0 and 84.
What it assumes
Assumes familiarity with pipelines and CIM instances while demonstrating method discovery from zero.
What you can do after
Operate/configure network adapters by discovering and invoking CIM methods, then interpreting their return values.
How it connects
Connects CIM objects with Get-CimClass, Get-CimInstance, WMI methods, and DHCP configuration.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.