我试图在 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/