Microsoft Virtualization Discussions

Test-Path

tyrone_owen_1
3,026 Views

Hi,

 

Hope you can help.

 

I want to get the IP address of a SVM's cifs lif into a variable and use this variable in Test-Path, but I can't work out what's happening:

 

 

 

$newshare = share_test
$activevserverip = Get-NcNetInterface -Vserver $activevserver -DataProtocols cifs | Select-Object Address

PS C:\Windows\system32> $activevserverip

Address 
------- 
xxx.xxx.21.10

Test-Path "\\$activevserverip\$newshare" -verbose

False

 

 

 

I receive a 'false' even though I know the path is up and accessible. What am I doing wrong please? Is it something like the data type of the IP address? If I create a path variable the IP address details are enclosed in a hash table (?). How can I reduce it to just the IP address?

 

PS C:\Windows\system32> $path = "\\$activevserverip\$newshare"

PS C:\Windows\system32> $path
\\@{Address=xxx.xxx.21.10}\share_test

 

Sorry if this is basic

Thanks

1 ACCEPTED SOLUTION

GidonMarcus
2,963 Views

Use as

 

Test-Path "\\$($activevserverip.address)\$newshare" -verbose

 

Gidi Marcus (Linkedin) - Storage and Microsoft technologies consultant - Hydro IT LTD - UK

View solution in original post

4 REPLIES 4

GidonMarcus
2,964 Views

Use as

 

Test-Path "\\$($activevserverip.address)\$newshare" -verbose

 

Gidi Marcus (Linkedin) - Storage and Microsoft technologies consultant - Hydro IT LTD - UK

tyrone_owen_1
2,943 Views

Brilliant, thank you.

 

I can see why that works, however I'm not sure why the below doesn't filter down to just the address:

 

>$activevserverip = Get-NcNetInterface -Vserver $activevserver -DataProtocols cifs | Select-Object Address

>activevserverip

Address 
------- 
10.4.0.9

 

Any links that you could share which would explain this please?

 

Thanks again

GidonMarcus
2,927 Views

Hi,

 

As in the example below you can get the type by piping the output to GM (get-member).

With using only the "select" - you still have it in a structured data type (in my get-disk example below "Selected.Microso...."), As test-parh don't know this odd data-type ,  you have to extract it into a format it expects (can see in get-help test-path it expects a string). 

PS C:\Users\g> get-help Test-Path

NAME
Test-Path

SYNTAX
Test-Path [-Path] <string[]> [-Filter <string>]..........

 

PS C:\Users\g> Get-Disk | select FriendlyName | gm


TypeName: Selected.Microsoft.Management.Infrastructure.CimInstance

Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
FriendlyName NoteProperty string FriendlyName=INTEL SSDSC2BF180A5L

 

PS C:\Users\g> (Get-Disk).FriendlyName
INTEL SSDSC2BF180A5L
PS C:\Users\g> (Get-Disk).FriendlyName | gm


TypeName: System.String

Name MemberType Definition
---- ---------- ----------
Clone Method System.Object Clone(), System.Object ICloneable.Clone()

.......

Gidi Marcus (Linkedin) - Storage and Microsoft technologies consultant - Hydro IT LTD - UK

tyrone_owen_1
2,923 Views

Thanks for the additional info - very helpful

Public