本帖最后由 小白龙 于 2026-4-10 05:44 编辑
下面的代码, 在我的电脑上有输出(pwsh7), 但是在另一台电脑(powershell5.1)上报后面的错误, 按我的理解, 电脑上不都有启动分区吗?
- wmic partition where "BootPartition=TRUE" get Index, DiskIndex, Size, Type
复制代码
错误信息:
wmic : GET 表达式无效。
所在位置 行:2 字符: 1
+ wmic partition where "BootPartition=TRUE" get Index, DiskIndex, Size, ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (GET 表达式无效。:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
------------------------------------------------------------------------------------------------------------------------------------------
好奇怪呀, 下面是测试步骤:
PS C:\Users\Administrator> wmic partition where "BootPartition=TRUE" get Index
Index
0
0
PS C:\Users\Administrator> wmic partition where "BootPartition=TRUE" get Index,DiskIndex
DiskIndex Index
1 0
0 0
PS C:\Users\Administrator> wmic partition where "BootPartition=TRUE" get Index,DiskIndex,Size
DiskIndex Index Size
1 0 64421363712
0 0 85893054464
PS C:\Users\Administrator> wmic partition where "BootPartition=TRUE" get Index,DiskIndex,Size,Type
DiskIndex Index Size Type
1 0 64421363712 Installable File System
0 0 85893054464 Installable File System
PS C:\Users\Administrator> wmic partition where "BootPartition=TRUE" get Index, DiskIndex, Size, Type
GET 表达式无效。
问题已经解决, 这是个大坑, 在powershell5.1中, get后面的必须直接用,不能用空格 |