Static methods, static properties and class methods, class property examples that call. NET objects in PowerShell _powershell

Source: Internet
Author: User

This article describes how to use. NET objects in PowerShell, PowerShell internally supports a large number of. NET objects.

Calling a static method of a class

Enclose the class name in brackets, enter a two colon, and then enter the method name, and finally the method's arguments. The syntax is as follows:

[Class name]:: Method Name (argument list)

Such as:

Copy Code code as follows:
[System.diagnostics.process]::getprocessbyid (0)

To access the static properties of a class

To access. NET class, you can enclose the name of the class by using brackets, then enter a two colon, and then enter the property name. The syntax is as follows:
[Class name]:: Property name
Such as:

Copy Code code as follows:
[System.datetime]::now

Method of calling Object

After the object variable, use the dot (.) as the member variable, followed by the method name, and the method argument. The syntax is as follows:
$ object variable. Method (parameter list)
Such as:

Copy Code code as follows:
$process = get-process Notepad
$process. WaitForExit ()

Accessing the properties of an object

Use the dot (.) as the member variable after the object variable, and then add the property name. The syntax is as follows:
$ object variable. Property name
Such as:

Copy Code code as follows:
$a =1,2,3
$a. Count

About the use of. NET objects in PowerShell, this article on the introduction of so many, I hope to help you, thank you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.