"Frank" <Frank@discussions.microsoft.com> wrote in message
news:AD5E7CA4-AFAC-43EE-9244-58760DC78F11@microsoft.com...
> Hi,
>
> I am doing a query via gwmi to see if a disk volume exists by its label
> via:
>
> $stat = gwmi win32_logicaldisk -computer testsvr | ? {$_.volumename -eq
> "test")
>
> When I test for $?, it is always "true". What is the best way to see if
> the
> volume exists? I think $stat | measure-object would work but what is
> recommended?
>
> Thanks in advance,
>
>
>
>

Adding to Frank's example, I would use server side filtering to return the
relevant logical disk only (if exist). the -Filter
parameter specifies a where clause thus you dont need the where-object cmdlet:

if(gwmi win32_logicaldisk -filter "volumeName = 'test'"){...}

-----
Shay Levi
$cript Fanatichttp://scriptolog.blogspot.com
> Hi,
>
> I am doing a query via gwmi to see if a disk volume exists by its
> label via:
>
> $stat = gwmi win32_logicaldisk -computer testsvr | ? {$_.volumename
> -eq "test")
>
> When I test for $?, it is always "true". What is the best way to see
> if the volume exists? I think $stat | measure-object would work but
> what is recommended?
>
> Thanks in advance,
>