使用“Format-Volume”cmdlet 格式化没有盘符的 RAM 磁盘
Format a RAM disk with no drive letter by using `Format-Volume` cmdlet
背景
我有一个用 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-Volume
、Get-CimInstance Win32_Volume
或 Get-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
也 returns 以下错误。
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
我在用户论坛上确认 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 无论如何都需要管理员权限。
背景
我有一个用 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-Volume
、Get-CimInstance Win32_Volume
或 Get-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
也 returns 以下错误。
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
我在用户论坛上确认 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 无论如何都需要管理员权限。