【问题标题】:Querying partitions/drives on a remote server with WMI使用 WMI 查询远程服务器上的分区/驱动器
【发布时间】:2012-05-10 20:18:14
【问题描述】:

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

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

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

【问题讨论】:

    标签: powershell wmi


    【解决方案1】:
    Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" | 
    Foreach-Object {$_.DeviceID}
    

    【讨论】:

    • 如果对 DriveType 进行解释会有所帮助... docs 说 DriveType 3 表示 Local Disk5 是光盘)。
    • 非常感谢!这就是我最终做的事情(实际上我在您发布解决方案之前就发现了它:))
    【解决方案2】:

    试试这个:

    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
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-25
        • 2013-10-17
        • 2019-06-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多