首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用` Format -Volume` cmdlet格式化不带驱动器号的RAM磁盘

使用` Format -Volume` cmdlet格式化不带驱动器号的RAM磁盘
EN

Stack Overflow用户
提问于 2020-05-10 03:24:08
回答 1查看 423关注 0票数 1

背景

我有一个用ImDisk工具包创建的内存盘。驱动器号是"R“。我可以正确地访问RAM盘(Get-ChildItem R:正确地显示目录条目)。

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

问题

当我尝试使用Format-Volume PowerShell cmdlet格式化内存磁盘时,遇到以下错误:

代码语言:javascript
运行
复制
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

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

代码语言:javascript
运行
复制
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属性的内存磁盘,但无法访问该属性。FriendlyName似乎不是实际的属性(它没有与Get-Member一起列出)。所以我不能过滤Get-Volume的结果并将其传递给Format-Volume

问题

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

编辑

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

代码语言:javascript
运行
复制
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时出现了以下错误。

代码语言:javascript
运行
复制
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还返回以下错误。

代码语言:javascript
运行
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-19 00:40:41

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

注意:我还尝试格式化了一个用Dataram RAMDisk制作的随机存取存储器磁盘。它有一个用于卷装载管理器的接口,但Format-Volume -DriveLetter S最终需要管理员权限。

代码语言:javascript
运行
复制
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似乎都需要管理员权限。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61702468

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档