AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 571354
Accepted
Kev
Kev
Asked: 2014-02-01 09:57:53 +0800 CST2014-02-01 09:57:53 +0800 CST 2014-02-01 09:57:53 +0800 CST

如何根据事件日志中报告的卷名识别 WMI 中的卷?

  • 772

我有一个报告以下错误的 Windows 2008R2 服务器:

磁盘上的文件系统结构已损坏且无法使用。请在卷\Device\HarddiskVolume2上运行 chkdsk 实用程序。

使用 Powershell 和 WMI 如何在查询时识别这是哪个卷Win32_Volume。

例如,如果我这样做:

Get-WmiObject Win32_Volume

我得到了服务器上所有卷的列表,但是没有一个Win32_Volume类属性使用(看起来是)这个“友好”名称 - \Device\HarddiskVolume2。我可以看到有一个DeviceID属性返回这样的值:

DeviceID    : \\?\Volume{4bc3df2a-65c7-11e0-9c33-806e6f6e6963}\

还有一个Name属性,但这只是分配给卷的驱动器号。其他任何属性都没有一个与事件日志中报告的内容相近的值。

我知道我可以解析输出fltmc volumes或DISKPART获取此信息,但必须有一种方法可以在 PowerShell 脚本中使用 WMI 来获取此信息。

我还查看了Win32_DiskDrive,Win32_DiskPartition和Win32_LogicalDisk类,但没有提到类似的属性值\Device\HarddiskVolume2。

windows
  • 2 2 个回答
  • 7436 Views

2 个回答

  • Voted
  1. Best Answer
    GµårÐïåñ
    2014-02-03T09:55:39+08:002014-02-03T09:55:39+08:00

    看看这段代码: http: //poshcode.org/4768它似乎做了你需要的转换来看看你想要什么,你也许可以调整它以满足你的需要,如果你需要帮助,请告诉我但我认为你可以自己弄清楚。

    function Get-DevicePath
    {
    <#
    .SYNOPSIS
    
        Returns the device paths for each volume.
    
        Author: Matthew Graeber (@mattifestation)
        License: BSD 3-Clause
    
    .DESCRIPTION
    
        Get-DevicePath returns the corresponding device path for each drive letter. This is useful for converting device paths to drive letters.
    
    .EXAMPLE
    
        Get-DevicePath
    
        DevicePath              DriveLetter
        ----------              -----------
        \Device\HarddiskVolume2 D:
        \Device\HarddiskVolume4 C:
    
    .OUTPUTS
    
        PSObject[]
    
        For each mount point, a PSObject is returned representing the drive letter and device path.
    #>
    
        # Utilize P/Invoke in order to call QueryDosDevice. I prefer using 
        # reflection over Add-Type since it doesn't require compiling C# code.
        $DynAssembly = New-Object System.Reflection.AssemblyName('SysUtils')
        $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly($DynAssembly, [Reflection.Emit.AssemblyBuilderAccess]::Run)
        $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule('SysUtils', $False)
    
        # Define [Kernel32]::QueryDosDevice method
        $TypeBuilder = $ModuleBuilder.DefineType('Kernel32', 'Public, Class')
        $PInvokeMethod = $TypeBuilder.DefinePInvokeMethod('QueryDosDevice', 'kernel32.dll', ([Reflection.MethodAttributes]::Public -bor [Reflection.MethodAttributes]::Static), [Reflection.CallingConventions]::Standard, [UInt32], [Type[]]@([String], [Text.StringBuilder], [UInt32]), [Runtime.InteropServices.CallingConvention]::Winapi, [Runtime.InteropServices.CharSet]::Auto)
        $DllImportConstructor = [Runtime.InteropServices.DllImportAttribute].GetConstructor(@([String]))
        $SetLastError = [Runtime.InteropServices.DllImportAttribute].GetField('SetLastError')
        $SetLastErrorCustomAttribute = New-Object Reflection.Emit.CustomAttributeBuilder($DllImportConstructor, @('kernel32.dll'), [Reflection.FieldInfo[]]@($SetLastError), @($true))
        $PInvokeMethod.SetCustomAttribute($SetLastErrorCustomAttribute)
        $Kernel32 = $TypeBuilder.CreateType()
    
        $Max = 65536
        $StringBuilder = New-Object System.Text.StringBuilder($Max)
    
        Get-WmiObject Win32_Volume | ? { $_.DriveLetter } | % {
            $ReturnLength = $Kernel32::QueryDosDevice($_.DriveLetter, $StringBuilder, $Max)
    
            if ($ReturnLength)
            {
                $DriveMapping = @{
                    DriveLetter = $_.DriveLetter
                    DevicePath = $StringBuilder.ToString()
                }
    
                New-Object PSObject -Property $DriveMapping
            }
        }
    }
    
    • 3
  2. SpiderIce
    2014-02-01T13:05:59+08:002014-02-01T13:05:59+08:00

    不确定这是否是您正在寻找的那种答案,但从我从命令行中看到的内容来看,这些数据在 Windows 中的列出并不好。我试图从 diskpart 中提取数据以显示信息,但没有列出设备名称。附带说明一下,2012 中似乎添加了更多磁盘命令,例如 get-volume、get-disk 和 get-physicaldisk,但这对 2008 没有帮助。

    一些 3rd 方实用程序会做到这一点

    1. http://www.chrysocome.net/dd只需要运行“dd --list”
    2. http://nirsoft.net/utils/drive_letter_view.html

    这两个实用程序都有命令行选项,因此应该能够将它们与 powershell 脚本一起使用。

    • 0

相关问题

  • 知道任何适用于 Windows 的快速可编写脚本的 ftp 客户端吗?[关闭]

  • 如果 Windows 服务崩溃,如何自动重新启动它?

  • 无法安排任务(访问被拒绝)

  • 物理机重启时自动重启虚拟机(VMWare)

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve