简体   繁体   English

如何使用Get-PSDrive仅列出有效的已装入磁盘分区?

[英]How do I list only the valid mounted disk partitions using Get-PSDrive?

I just discovered PowerShell literally yesterday and I love it. 我昨天刚刚发现了PowerShell,我很喜欢它。

I am trying to list all the valid mounted partitions so I can make them a variable and run chkdsk on them. 我试图列出所有有效的已安装分区,以便我可以将它们变为变量并对它们运行chkdsk The problem is that I don't want to detect backup partitions on the machine. 问题是我不想检测机器上的备份分区。 The computer I'm using to write and test this script doesn't have any backup/not-mounted partitions. 我用来编写和测试此脚本的计算机没有任何备份/未挂载的分区。 I am thoroughly reading get-help get-psdrives but I don't have the knowledge to understand if the options can do what I need (or if they already are doing it). 我正在彻底阅读get-help get-psdrives但是我没有足够的知识来理解这些选项是否可以做我需要的(或者如果他们已经这样做了)。

This will get you all the drives that you can run chkdsk on: 这将为您提供所有可以运行chkdsk的驱动器:

Get-PSDrive -PSProvider FileSystem

Edit: This will get you the mounted drives that are either Local Disks (3) or removable disks (2) : 编辑:这将为您提供已安装的驱动器,它们是本地磁盘(3)或可移动磁盘(2)

Get-WmiObject -class “Win32_LogicalDisk" | ?{ @(2, 3) -contains $_.DriveType }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM