【问题标题】:Format a RAM disk with no drive letter by using `Format-Volume` cmdlet使用 `Format-Volume` cmdlet 格式化没有驱动器号的 RAM 磁盘
【发布时间】:2020-08-25 09:16:35
【问题描述】:

背景

我有一个使用 ImDisk Toolkit 创建的 RAM 磁盘。驱动器号为“R”。我可以正确访问 RAM 磁盘(Get-ChildItem R: 正确显示目录条目)。

我想在没有管理员权限的情况下在我的 powershell 脚本(它运行基准测试)中格式化 RAM 磁盘。所以我想避免使用format 命令,因为它需要管理员权限才能执行。

问题

当我尝试使用Format-Volume PowerShell cmdlet 格式化 RAM 磁盘时,出现以下错误:

PS C:\> Format-Volume -DriveLetter R
Format-Volume : No MSFT_Volume objects found with property 'DriveLetter' equal to 'R'.  Verify the value of the
property and retry.
At line:1 char:1
+ Format-Volume -DriveLetter R
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (R:Char) [Format-Volume], CimJobException
    + FullyQualifiedErrorId : CmdletizationQuery_NotFound_DriveLetter,Format-Volume

我发现 RAM 磁盘似乎没有来自 PowerShell 的驱动器号(带有Get-Volume)。

DriveLetter FriendlyName     FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining     Size
----------- ------------     -------------- --------- ------------ ----------------- -------------     ----
E                            Unknown        Fixed     Healthy      Unknown                     0 B      0 B
C           Windows          NTFS           Fixed     Healthy      OK                    334.99 GB 475.7 GB
            Windows RE tools NTFS           Fixed     Healthy      OK                    504.46 MB   990 MB

我尝试选择具有FriendlyName 属性的RAM 磁盘,但我无法访问该属性。 FriendlyName 似乎不是实际财产(它没有与Get-Member 一起列出)。所以我无法过滤Get-Volume 的结果并将其传递给Format-Volume

问题

如何使用Format-Volume cmdlet 指定要格式化的 RAM 磁盘,而 Get-Volume 似乎没有驱动器号?或者,在这种情况下我是否必须使用format 命令而不是Format-Volume cmdlet(所以我必须具有管理员权限)?

编辑

我发现RAM磁盘没有出现在Get-VolumeGet-CimInstance Win32_VolumeGet-CimInstance Win32_DiskPartition的结果中。它只出现在Get-CimInstance Win32_LogicalDisk 的结果中,如下所示:

PS C:\> Get-CimInstance Win32_LogicalDisk

DeviceID DriveType ProviderName VolumeName Size          FreeSpace
-------- --------- ------------ ---------- ----          ---------
C:       3                      Windows    510781288448  353026121728
E:       3
R:       3                                 1073737728    1056030720
Z:       3                                 3897664995328 3646232199168

请注意,RAM 磁盘 (R:) 显示为 DriveType 3(固定磁盘)。

我可以获取 RAM 磁盘 (R:) 的对象,但 Format-Volume 出现以下错误。

PS C:\> $ramDisk = Get-CimInstance Win32_LogicalDisk | Where-Object { $_.DeviceID -eq "R:" }
PS C:\> Format-Volume -Partition $ramDisk -WhatIf
Format-Volume : Cannot bind argument to parameter 'Partition', because PSTypeNames of the argument do not match the
PSTypeName required by the parameter: Microsoft.Management.Infrastructure.CimInstance#MSFT_Partition.
At line:1 char:26
+ Format-Volume -Partition $ramDisk -WhatIf
+                          ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Format-Volume], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : MismatchedPSTypeName,Format-Volume

编辑 2

Format-Volume -InputObject 也返回以下错误。

PS C:\> $ramDisk = Get-CimInstance Win32_LogicalDisk | Where DeviceId -eq 'R:'
PS C:\> $ramDisk

DeviceID DriveType ProviderName VolumeName Size       FreeSpace
-------- --------- ------------ ---------- ----       ---------
R:       3                                 1073737728 1056030720

PS C:\> Format-Volume -InputObject $ramDisk -WhatIf
Format-Volume : Cannot bind argument to parameter 'InputObject', because PSTypeNames of the argument do not match the P
STypeName required by the parameter: Microsoft.Management.Infrastructure.CimInstance#MSFT_Volume.
At line:1 char:28
+ Format-Volume -InputObject $ramDisk -WhatIf
+                            ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Format-Volume], ParameterBindingArgumentTransformationException
    + FullyQualifiedErrorId : MismatchedPSTypeName,Format-Volume

【问题讨论】:

  • 重新编辑 2:它正在寻找一个特定的 CimInstance 子类型,如果你愿意的话:MSFT_Volume,正如 Get-Volume 所报告的那样(完整的 ETS 类型名称是 Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_Volume)。跨度>

标签: powershell format ramdisk


【解决方案1】:

我在用户论坛上确认了ImDisk has no interface for Volume Mount Manager。所以无法用Format-Volume cmdlet 格式化ImDisk 制作的RAM 盘。

注意:我也尝试过格式化使用Dataram RAMDisk 制作的 RAM 磁盘。它有一个Volume Mount Manager的接口,但Format-Volume -DriveLetter S最终需要管理员权限。

PS C:\> Format-Volume -DriveLetter S
Format-Volume : Access Denied
Activity ID: {1c815d1b-72f2-4432-b0e1-a33c96d2f539}
At line:1 char:1
+ Format-Volume -DriveLetter S
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : PermissionDenied: (StorageWMI:ROOT/Microsoft/...age/MSFT_Volume) [Format-Volume], CimExc
   eption
    + FullyQualifiedErrorId : StorageWMI 40001,Format-Volume

看来Format-Volume cmdlet 无论如何都需要管理员权限。

【讨论】:

    猜你喜欢
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2012-08-07
    相关资源
    最近更新 更多