PowerShell Class


#https://overpoweredshell.com//Introduction-to-PowerShell-Classes/ class Person {
hidden
[ValidatePattern(‘^[a-z]’)]
[ValidateLength(3,15)]
[string]$Name = “Wang” #default value
[ValidateRange(1000,100000)]
static[int]$Id
Person() {}
Person([string]$Name) {
$this.Name = $Name }
[string]GetName([string]$UserName){
return $UserName }
[string]GetName(){ return ($this.Name) } }
class child:Person #继承了父类的属性及方法
{ } $one=[Person]::new()
$two=[Person]::new(“lang”)
$one|gm -Force #获取隐藏属性
$child=[child]::new()

本文链接: https://www.pstips.net/powershell-class.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

发表评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注