I wanted to separate the creation of a System.Object but can't work with it properly.
- Code: Select all
function Get-NSObject([string]$name, [string]$ip)
{
$NSObject = New-Object System.Object |
Add-Member NoteProperty Name '' -PassThru |
Add-Member NoteProperty IP'' -PassThru
return $NSObject
}
function Main()
{
$NSObject = Get-NSObject("Test", "127.0.0.1")
# I can output it, no problem
write-host ($NSObject | out-string)
# However, I can't get the Properties:
write-host $NSObject.IP
}
So, how do I get Powershell to return the full System.Object instead of something I can't work with.
I already tried: return [System.Object]$NSObject # but that didn't solve my problem.
