我试图在Windows 2008服务器上找到不是“C,E,L,S,T,W”的每个驱动器号。谁能告诉我我的逻辑中的错误或我怎么能这样做?
[char[]]”CELSTW” | Where-Object {!(Get-PSDrive $_ )}
答案 0 :(得分:5)
您将开始使用您不想要的驱动器号列表(CELSTW)并输出那些不存在的驱动器号作为psdrive。
你想要的是从所有PSDrives的列表开始,并过滤掉它们与你不想要的匹配的地方:
Get-PSDrive | Where-Object { [char[]]"CELSTW" -notcontains $_.Name }
虽然这会给你一堆其他的PSDrive类型。您可能还想为FileSystem提供程序过滤它:
Get-PSDrive | Where-Object { [char[]]"CELSTW" -notcontains $_.Name -AND $_.Provider.Name -eq "FileSystem"}
答案 1 :(得分:1)
这应该给你所有的psdrives名称(driveletter)不是“C,E,L,S,T,W”
Get-PSDrive | ?{[char[]]"CELSTW" -notcontains $_.name}
但是,如果要排除非文件系统psdrives,请尝试以下操作:
Get-PSDrive | ?{[char[]]"CELSTW" -notcontains $_.name} | ?{$_.Provider.name -eq "FileSystem"}
答案 2 :(得分:0)
你必须从另一端去做这件事:
$drives = [char[]]"CD"
Get-PSDrive | ? { $drives -notcontains $_.Name}
答案 3 :(得分:0)
使用-notmatch运算符的另一个例子:
Get-PSDrive | Where-Object { $_.Name -notmatch '[CELSTW]'}