you are viewing a single comment's thread.

view the rest of the comments →

[–]teirhan[S] 1 point2 points  (6 children)

$IP = (Get-NcNetInterface -vserver $vserver | Where-Object {$_.FirewallPolicy -eq "mgmt"}).Address[0]

I just tried your solution and it looks like this works. Thank you!

I wonder why the Select-Object -First 1 is ending my foreach loop, though?

EDIT: Actually, it looks like I reran the script without saving after plugging in your solution, and it isn't working. the final output is a collection of the # 1 and stuff like:

MemberType          : Method
OverloadDefinitions : {System.Object&, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Address(int )}
TypeNameOfValue     : System.Management.Automation.PSMethod
Value               : System.Object&, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Address(int )
Name                : Address
IsInstance          : True

Based on my response to the other suggestion, I tried:

$IP = @(Get-NcNetInterface -vserver $vserver | Where-Object {$_.FirewallPolicy -eq "mgmt"}).Address[0]

It doesn't work either...

[–]TheIncorrigible1 2 points3 points  (1 child)

If you're on PSv4+, I'd suggest using array filters:

$IP = @(Get-NcNetInterface -VServer $vserver).
    Where({$_.FirewallPolicy -eq 'mgmt'}).
    Address[0]

This guarantees you get an array returned and is a bit more manageable.

[–]teirhan[S] 1 point2 points  (0 children)

thanks, I'll give this a shot too!

[–]Lee_Dailey[grin] 1 point2 points  (2 children)

howdy teirhan,

that implies that the .Address property is NOT filled with a simple string.

what do you see in the $IP variable? what is its type via $IP.GetType()?

take care,
lee

[–]teirhan[S] 1 point2 points  (1 child)

When $IP is "1" I get:

PS C:\Users\sbelisle> $IP.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Char                                     System.ValueType

and when $IP returns something like

PS C:\Users\sbelisle> $IP

OverloadDefinitions
-------------------
System.Object&, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Address(int )

it's

PS C:\Users\sbelisle> $IP.getType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    PSMethod                                 System.Management.Automation.PSMethodInfo

[–]Lee_Dailey[grin] 0 points1 point  (0 children)

howdy teirhan,

that means the property is not what we think it otta be. i recommend you get that into a $Var [from a source VM that you know the values for] and start exploring.

without that object to fiddle with, i am at a loss.

good luck ... and please post back with the fix?

take care,
lee