将Get-Childitem的输出合并到[System.Reflection.Assembly] :: LoadFrom(...)

时间:2018-06-26 13:43:20

标签: powershell

我正在尝试在硬盘中搜索具有特定名称的所有程序集,并同时检查其版本。我的问题是如何将Get-Childitem的输出重定向到LoadFrom(x)。 以下命令列出了我要搜索的所有程序集:

Get-Childitem –Path C:\ -Include Microsoft.SqlServer.ConnectionInfo.dll -Recurse -ErrorAction SilentlyContinue 

,同时我想使用以下命令查看程序集版本:

[System.Reflection.Assembly]::LoadFrom("C:\....\Microsoft.SqlServer.ConnectionInfo.dll").GetName().Version

有可能吗?

1 个答案:

答案 0 :(得分:3)

您可以使用ForEach-Object循环,但我也建议您在-Filter上使用-Include来提高速度:

Get-Childitem -Path C:\ -Filter Microsoft.SqlServer.ConnectionInfo.dll -Recurse -ErrorAction Ignore |
    ForEach-Object {
        "Checking: $($PSItem.FullName)"
        [System.Reflection.Assembly]::LoadFrom($PSItem.FullName).GetName().Version
    }