Powershell Problem returning an Object

Talk about any languages right here. Share and discuss source, but don't expect your homework to be done for you.

Powershell Problem returning an Object

Postby Tenchuu » Thu Oct 29, 2009 11:53 pm

Hi,

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.
User avatar
Tenchuu
Reborn
 
Posts: 1160
Joined: Tue Mar 16, 2004 3:27 pm
Location: Society of Blazing Inferno

Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests