酷云的csdn 2020-01-06
#创建对象
$pocketknife=New-Object object
#增加属性
Add-Member -InputObject $pocketknife -Name Color -Value "Red" -MemberType NoteProperty
#增加方法
# 增加一个新方法:
Add-Member -memberType ScriptMethod -In $pocketknife ` -name cut -Value { "I‘m whittling now" }
# 指定参数类型增加一个新方法:
Add-Member -in $pocketknife ScriptMethod screw { "Phew...it‘s in!" }
#直接通过管道增加一个新方法:
$pocketknife | Add-Member ScriptMethod corkscrew { "Pop! Cheers!" }
$pocketknife.cut()