我无法让脚本正常工作。 我有三个数组。 extensions数组过滤正确。然而我的通配符数组并没有产生我想要的结果。我究竟做错了什么?Where-Object和阵列未正确过滤
# Read List of Servers from flat file
$data=Get-Content C:\myscripts\admin_servers.txt
# Variables that will be used against search parameter
$extensions = @(".ecc", ".exx", ".ezz", ".vvv")
$wildcards = @("Help_*.txt", "How_*.txt", "Recovery+*")
$exclude = @("help_text.txt", "Lxr*.exx", "help_contents.txt")
# Loop each server one by one and do the following
foreach ($server in $data)
{
# Search the server E:\ and all subdirectories for the following types of
# extensions or wildcards.
Get-ChildItem -path \\$server\e$ -Recurse | Where-Object {
(($extensions -contains $_.Extension) -or $_.Name -like $wildcards) -and
$_.Name -notlike $exclude
}
}
'$ _名状$ wildcards'是比较'$ _ Name'来。数组。您需要将'$ _。Name'与数组中的每个值进行比较。 –
所以我需要为每个值添加-or和 - 语句? [0],[1],[2]等?有没有办法来减少?我希望数组能够工作,而不必在where子句中指定每个值。 – Refried04
这样做:'($ wildcards |%{“help_a.txt”-like $ _})。Contains($ true)'。可能有一个更简洁的方法。我硬编码一个文件名来测试它,但我认为你明白了。 –