windows - powershell:get-psdrive 和 where-object

标签 windows powershell logic

我试图在 Windows 2008 服务器上查找不是“C、E、L、S、T、W”的每个驱动器号。谁能告诉我我逻辑上的错误或我该怎么做?

[char[]]”CELSTW” | Where-Object {!(Get-PSDrive $_ )} 

最佳答案

您从不需要的驱动器号列表 (CELSTW) 开始,并将不存在的驱动器号输出为 psdrive。

您想要的是从所有 PSDrive 的列表开始,然后在与您不想要的相匹配的地方过滤掉它们:

Get-PSDrive | Where-Object { [char[]]"CELSTW" -notcontains $_.Name }

虽然这会给你一堆其他的 PSDrive 类型。您可能还想为 FileSystem 提供程序过滤它:

 Get-PSDrive | Where-Object { [char[]]"CELSTW" -notcontains $_.Name -AND $_.Provider.Name -eq "FileSystem"}

关于windows - powershell:get-psdrive 和 where-object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10558977/

相关文章:

php - 使用经度和纬度查找彼此靠近的城市

php - 从文本 blob 中检测名字和姓氏的最佳方法

boolean - 参数化模块 (SystemVerilog)

c++ - ReadDirectoryChangesW 和 GetOverlappedResult

c++ - 打印 NaN 值

arrays - 是否可以在 Powershell 中将字节数组转换为 8 位有符号整数数组?

powershell - 通过多个 if 语句传递字符串,每个语句都有一个 else

azure - PowerShell 获取 Azure API 报告?

c++ - 从 32 位应用程序打开 64 位注册表编辑器

windows - Git 管理的文件中出现外来字符