我已经创建了一个返回自定义 psobject的函数,但是当我尝试使用“ . ”来获取对象的属性时,注意到发生了,管道也不能在这种类型的对象中工作。
有一种方法可以将此对象转换为使用 cmdlet New-object 创建的对象?
为什么新的 psobject 缺少功能?
$ObjectProperties = @{
Users = "admin"
Computer = "localhost"
Error = $false
}
$Objects += New-Object psobject -Property $ObjectProperties
# I am trying to use select this object like $objects.computer but doesnt work
$Objects.
$objectTest = New-Object Object
$objectTest | Add-Member NoteProperty error $false
$objectTest | Add-Member NoteProperty Computadores "localhost"
$objectTest | Add-Member NoteProperty Usuarios "admin"
#I need an object like this that can be easy managed
$objectTest
我试过以这种方式转换它但不起作用
$objectCompu = $objects |select computer|Out-String
$objectError = $Objects |select error|Out-String
$objectUsers = $Objects |select users |Out-String
$objectTest = New-Object Object
$objectTest | Add-Member NoteProperty error $objectError
$objectTest | Add-Member NoteProperty Computadores $objectCompu
$objectTest | Add-Member NoteProperty Usuarios $objectUsers
$objectTest