我使用這個命令來獲得我的驅動器列表我Windows
:PowerShell的獲得驅動器列表
get-wmiobject win32_volume | ? { $_.DriveType -eq 3 } | % { get-psdrive $_.DriveLetter[0] }
這給:
Name Used (GB) Free (GB) Provider Root
---- --------- --------- -------- ----
C 131.85 333.62 FileSystem C:\
D 111.15 200.63 FileSystem D:\
我真正想要得到的是「根」列下的值列表。 基本上一個字符串如下C:\ D:\
我該怎麼做?
編輯:
我成功地做到這一點:
get-wmiobject win32_volume | ? { $_.DriveType -eq 3 } | % { get-psdrive $_.DriveLetter[0] } | Select Root
這給:
Root
----
C:\
D:\
如何將其轉換爲:
C:\ D:\
@LotPings:你在哪裏撿只有root。他希望只選擇根目錄 –
使用:'Select -Expand Root'但是您的查詢存在缺陷,具體取決於您可能獲得的驅動器(不可用)'無法在'get-psdrive $ __中編入空數組' .DriveLetter [0]' – iRon
@iRon你會如何解決它? – avi