【发布时间】: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-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 也返回以下错误。
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