TechTalkz.com Logo Ask the Experts!

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Microsoft > Microsoft Windows Powershell

How to check for existence of disk volume by label

Microsoft Windows Powershell

 
 
 
Thread Tools Display Modes
Old 01-05-2008, 01:26 AM   #1
Frank
Guest
 
Posts: n/a
How to check for existence of disk volume by label

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,




 
Old 01-05-2008, 03:19 AM   #2
Brandon [MVP]
Guest
 
Posts: n/a
Re: How to check for existence of disk volume by label

I would use if(){}

if(gwmi win32_logicaldisk -computer testsvr | ? {$_.volumename -eq "test"))
{
... Your code here
}

"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,
>
>
>
>


 
Old 01-05-2008, 12:20 PM   #3
Shay Levi
Guest
 
Posts: n/a
Re: How to check for existence of disk volume by label


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 Fanatic
http://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,
>



 
 

Thread Tools
Display Modes



< Home - Windows Help - MS Office Help - Hardware Support >


New To Site? Need Help?

All times are GMT. The time now is 04:31 AM.


vBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2013, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional