嘿伙计们,
所以我在 powershell 中编写了一个小脚本(对此非常新)。大约 10 年没有碰过任何东西,但事情是这样的:
该脚本应该从 c:\上的特定文件夹中为我在网络上的所有计算机(包括我在不同州的 sibling 的一些计算机)提取证书日期,并将结果作为文本文件保存在我的桌面上。
我只是对这个扩展感到好奇。如果文件夹中有多个具有不同扩展名的证书,我可以使用 -eq 使用同一行提取两个扩展名的数据。假设文件夹路径是 C:\List\certificates (不会从证书存储中提取任何数据,因此没有 pfx 文件),我在代码中使用了这一行:
$certificates = Get-ChildItem -Path $using:certPath -Recurse | Where-Object { $_.Extension -eq “.cer .key”}
最佳答案
您可以使用 containment operator为此,-in
或 -contains
:
$certificates = Get-ChildItem -Path $using:certPath -Recurse |
Where-Object Extension -In '.cer', '.key'
使用 Get-ChildItem
内置过滤参数 -Include
也应该有效:
$certificates = Get-ChildItem -Path $using:certPath -Recurse -Include *.cer, *.key
或者您可以使用 -Match
和正则表达式模式:
$certificates = Get-ChildItem -Path $using:certPath -Recurse |
Where-Object Extension -Match '\.(?:cer|key)$'
关于powershell - -eq 是否适用于 Powershell 中的多个扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77525866/