Share via

Powershell class's method's, propertis availability

Norbert Pozsonyi 1 Reputation point
2021-03-22T13:32:06.817+00:00

So when i would call a method of Win32_NetworkAdapterConfiguration class

Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration |?{$_.Description -match ".?Miniport.?"} -OutVariable iuz

with Where-object i get the properies correctly but how can i call the Description with sorter format
something like that

[Win32_NetworkAdapterConfiguration]::[Notation] for that what is the sintax?

So how can i call methods, properties through class name?

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2021-03-23T03:36:45.767+00:00

    Hi,

    The :: operator only works with static members of .net framework classes. To call methods of WMI classes you can use the Invoke-WmiMethod cmdlet.
    https://learn.microsoft.com/en-us/powershell/scripting/samples/using-static-classes-and-methods

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?

    0 comments No comments

  2. Norbert Pozsonyi 1 Reputation point
    2021-03-22T15:54:15.413+00:00

    Thank you for answear and if i write a expression like [Class]::Method() . When we use this in cas of traditional objects?

    Can you help me and Make an example?

    Was this answer helpful?


  3. Rich Matheisen 48,116 Reputation points
    2021-03-22T14:40:44.497+00:00

    WMI classes aren't the same as a traditional "object" class. The WMI class identifies the type (or class) of "thing" (or "things") you want information from (or about). Unlike "object" classes they have no constructors and no class methods. The WMI (or CIM) returns objects that represent the state of the "thing". The objects returned have both properties and methods.

    If all you want is the object's "Description" property you could do something like this:

    Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration | 
        Where-Object description -like "*miniport*" | 
            Select-Object Description
    

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.