PowerShell for Windows Admins

Feb 11 2010   4:07PM GMT

VolumeLabels



Posted by: Richard Siddaway
Tags:
Disks
PowerShell v2

Need to read just the volume labels on a system.  Try this

001
002
003
004
005
006
007
008
009
010
011
012
013
014
function Get-VolumeLabel {
param ([string]$computer=".",
       [string]$drive = $null
)
    if ($drive){
        if ($drive -notlike "?:")
        { Throw "Drive should be submitted as letter and colon e.g. C:"}
        $wmiq = Get-WmiObject -Class Win32_LogicalDisk `
         -Filter "DeviceId=’$($drive)’"  -Computer $computer
    }
    else {$wmiq = Get-WmiObject -Class Win32_LogicalDisk -Computer $computer}
   
    $wmiq | select DeviceId, VolumeName
}

 

Technorati Tags: ,

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: