SoFunction
Updated on 2025-03-04

Examples of static methods, static properties, class methods, and class attributes that call .NET objects in PowerShell

This article introduces how to use .NET objects in PowerShell. PowerShell supports a large number of .NET objects intrinsically.

Calling static methods of the class

Enclose the class name in brackets, then enter two colons, then enter the method name, and finally the method parameters. The syntax is as follows:

[Class name]:: Method name (parameter list)

like:

Copy the codeThe code is as follows:
[]::GetProcessById(0)

Access the static properties of the class

To access static properties of .NET classes, you can use brackets to enclose the class name, enter two colons, and then enter the property name. The syntax is as follows:
[Class Name]::Attribute Name
like:

Copy the codeThe code is as follows:
[]::Now

Methods to call objects

After the object variable, use point (.) as the member variable character, then add the method name and method parameters. The syntax is as follows:
$Object variable.Method (parameter list)
like:

Copy the codeThe code is as follows:
$process = Get-Process notepad
$()

Access the properties of the object

After the object variable, use the point (.) as the member variable character, and then add the attribute name. The syntax is as follows:
$Object variable.Attribute name
like:

Copy the codeThe code is as follows:
$a=1,2,3
$

This article introduces so much about the use of .NET objects in PowerShell. I hope it will be helpful to everyone. Thank you!