PowerShell的对象创建

创建对象

$mytest=new-object object
$mytest
显示:
System.Object

增加属性

$mytest | add-member noteproperty Name "test1"
$mytest | add-member noteproperty Age 3
$mytest | add-member noteproperty Height 1.89
$mytest | add-member noteproperty Likes "play computer"
$mytest
显示:
Name  Age Height Likes
----  --- ------ -----
test1   3   1.89 play computer

增加方法

$mytest | add-member scriptmethod method1 {"this is my method1"}
$mytest | add-member scriptmethod method2 {"this is my method2"}
$mytest | add-member scriptmethod method3 {"this is my method3"}
$mytest.method1()
显示:
    this is my method1
$mytest.method2()
显示:
    this is my method2
$mytest.method3()
显示:
    this is my method3

猜你喜欢

转载自blog.csdn.net/weixin_42917630/article/details/94553595