我有一个用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
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
我在用户论坛上确认ImDisk没有用于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似乎仍然需要管理员权限。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句