如何从 Powershell 输出中整理驱动器号
How to Sort Out Drive Letters from Powershell Output
所以我正在尝试制作一个 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:\
如何只打印没有列名的驱动器名称?
有两种方法可以从该 cmdlet 中获取您似乎想要的驱动器信息。一个获取 just 字母 [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.
所以我正在尝试制作一个 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:\
如何只打印没有列名的驱动器名称?
有两种方法可以从该 cmdlet 中获取您似乎想要的驱动器信息。一个获取 just 字母 [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.