使用WMI查询远程服务器上的分区/驱动器

时间:2012-05-10 11:24:51

标签: powershell wmi

我执行以下操作以检查远程计算机上的本地驱动器/分区:

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

但该命令也会返回CD-ROM等。 是否只有返回磁盘/分区的命令?

3 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:1)

试试这个:

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

答案 2 :(得分:0)

Get-WmiObject -query "Select * from Win32_DiskPartition" ...也许?