Sune
Sune

Reputation: 3280

Querying partitions/drives on a remote server with WMI

I do the following to check for local drives/partitions on a remote computer:

Get-WmiObject -Class Win32_Share -ComputerName SERVERNAME -Filter "Description='Default share'"

but the command also returns CD-roms etc. Is there a command to only return disk/partitions?

Upvotes: 1

Views: 7810

Answers (3)

Shay Levy
Shay Levy

Reputation: 126902

Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" | 
Foreach-Object {$_.DeviceID}

Upvotes: 3

CB.
CB.

Reputation: 60956

Try this:

Get-WMIObject Win32_DiskPartition  -computername remotecomp |

ForEach-Object {
$info = @{}
$info.Disk = $_.DiskIndex
$info.Partition = $_.Index 
$info.DriveLetter = $_.psbase.GetRelated('Win32_LogicalDisk') |     
Select-Object -ExpandProperty DeviceID    
    New-Object PSObject -Property $info
}

$info # contains partions number and unit letter as hashtable

Upvotes: 1

David Brabant
David Brabant

Reputation: 43569

Get-WmiObject -query "Select * from Win32_DiskPartition" ... maybe?

Upvotes: 0

Related Questions