0

因此,我正在尝试制作一个 for 循环,该循环将根据 Windows 中任何人的驱动器优化驱动器。我有以下命令,并且知道如何构造 for 循环。我只需要 jkust 打印驱动器号的命令。有没有办法用Get-PSDrive命令做到这一点?

PS C:\WINDOWS\system32> Get-PSDrive -PSProvider FileSystem

Name           Used (GB)     Free (GB) Provider      Root                                                                                   CurrentLocation
----           ---------     --------- --------      ----                                                                                   ---------------
C                1311.02        550.33 FileSystem    C:\                                                                                   WINDOWS\system32
D                 557.70        140.94 FileSystem    D:\
E                   0.22          0.46 FileSystem    E:\
F                   0.00        369.97 FileSystem    F:\
H                   0.23          1.14 FileSystem    H:\
J                1676.01          0.64 FileSystem    J:\
O                 899.72         31.79 FileSystem    O:\

如何只打印没有列名的驱动器名称?

4

1 回答 1

3

有两种方法可以从该 cmdlet 获取您似乎想要的驱动器信息。一个得到字母 [the .Name, ex = C],另一个得到驱动器的根目录 [the .Root, ex = C:\]。

只有盘符...

(Get-PSDrive -PSProvider FileSystem).Name
# result is an array of just the drive letters
#    C, D, E, etc.

驱动器的根...

(Get-PSDrive -PSProvider FileSystem).Root
# result is an array of drive roots
#    C:\, D:\, E:\, etc.
于 2020-04-01T18:43:17.463 回答