พื้นหลัง
ฉันมีดิสก์ RAM ที่สร้างด้วย ImDisk Toolkit อักษรระบุไดรฟ์คือ "R" ฉันสามารถเข้าถึงดิสก์ RAM ได้อย่างถูกต้อง (Get-ChildItem R:
แสดงรายการไดเรกทอรีอย่างถูกต้อง)
ฉันต้องการฟอร์แมตดิสก์ RAM ในสคริปต์ PowerShell ของฉัน (ใช้เกณฑ์มาตรฐาน) โดยไม่มีสิทธิ์ของผู้ดูแลระบบ ดังนั้นฉันจึงต้องการงดเว้นจากการใช้คำสั่ง format
เพราะจำเป็นต้องมีสิทธิ์ของผู้ดูแลระบบในการดำเนินการ
ปัญหา
เมื่อฉันพยายามฟอร์แมตดิสก์ RAM ด้วย Format-Volume
PowerShell cmdlet ฉันได้รับข้อผิดพลาดต่อไปนี้:
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
ฉันได้ลองเลือกดิสก์ RAM ที่มีคุณสมบัติ FriendlyName
แล้ว แต่ฉันไม่สามารถเข้าถึงคุณสมบัตินั้นได้ FriendlyName
ดูเหมือนจะไม่ใช่ทรัพย์สินที่แท้จริง (ไม่อยู่ในรายการด้วย Get-Member
) ดังนั้นฉันจึงไม่สามารถกรองผลลัพธ์ของ Get-Volume
และส่งต่อไปยัง Format-Volume
ได้
คำถาม
ฉันจะระบุดิสก์ RAM ให้ฟอร์แมตด้วย Format-Volume
cmdlet ที่ดูเหมือนว่าจะไม่มีอักษรระบุไดรฟ์ด้วย 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
CimInstance
เฉพาะ หากคุณต้องการ:MSFT_Volume
ตามที่รายงานโดยGet-Volume
(ชื่อประเภท ETS แบบเต็มคือMicrosoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_Volume
) - person mklement0   schedule 12.05.2020