具有通配符字符串通配符的Powershell搜索路径

时间:2017-12-07 14:32:55

标签: powershell

我正在尝试在日志文件中搜索未安装的更新,然后使用返回的阵列安装更新。问题是我的文件命名为:

Windows6.1-KB3102429-v2-x64.msu

我的解析数组有一个项KB3102429如何使用外卡 - 调用数组项 - 然后另一个外卡.msu

我的代码如下:

# Read KBLIST.txt and create array of KB Updates that were not installed
$Failed = Get-Content -Path C:/Updates/KBLIST.txt | Where-Object {$_ -like '*NOT*'}

# create a list of all items in Updates folder
$dir = (Get-Item -Path "C:\Updates" -Verbose).FullName

# Parse the $Failed array down to just the KB#######
for($i = $Failed.GetLowerBound(0); $i -le $Failed.GetUpperBound(0); $i++) 
{
    $Failed[$i][1..9] -join ""

    # Search the $dir list for files that contain KB####### and end in .msu then quiet install 
    Foreach($item in (ls $dir *$Failed[$i]*.msu -Name))
    {
        echo $item
        $item = "C:\Updates\" + $item
        wusa $item /quiet /norestart | Out-Null
    }
}

它适用于Foreach($item in (ls $dir *$Failed[$i]*.msu -Name))

如果我只使用*而不是wildcard,string,wildcard,则会返回所有.msu文件的列表,以获取正确的基本语法。

1 个答案:

答案 0 :(得分:1)

由于您使用了别名,因此很难跟进您的工作,但我认为这应该能够实现您所需的目标。

final_list=[]
for i in itertools.permutations(input,r=2):
    final_list.append((i[0]-i[1]))
print(final_list)
相关问题