ฟอร์แมตดิสก์ RAM โดยไม่มีอักษรระบุไดรฟ์โดยใช้ cmdlet `Format-Volume`

พื้นหลัง

ฉันมีดิสก์ 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


person SATO Yusuke    schedule 09.05.2020    source แหล่งที่มา
comment
แก้ไขอีกครั้ง 2: กำลังมองหาประเภทย่อย CimInstance เฉพาะ หากคุณต้องการ: MSFT_Volume ตามที่รายงานโดย Get-Volume (ชื่อประเภท ETS แบบเต็มคือ Microsoft.Management.Infrastructure.CimInstance#ROOT/Microsoft/Windows/Storage/MSFT_Volume)   -  person mklement0    schedule 12.05.2020


คำตอบ (1)


ฉันยืนยันที่ฟอรัมผู้ใช้ว่า ImDisk ไม่มีอินเทอร์เฟซสำหรับ Volume Mount Manager< /ก>. ดังนั้นจึงไม่มีวิธีฟอร์แมตดิสก์ RAM ที่สร้างด้วย ImDisk ด้วย Format-Volume cmdlet

หมายเหตุ: ฉันได้ลองฟอร์แมตดิสก์ RAM ที่สร้างด้วย Dataram RAMDisk. มีอินเทอร์เฟซสำหรับ 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 ต้องการสิทธิ์ของผู้ดูแลระบบอยู่แล้ว

person SATO Yusuke    schedule 18.05.2020