例如,我正在寻找这样的命令,该命令仅更新以 PackagePrefix
的名称开头的软件包:
Update-Package "PackagePrefix.*"
我尝试了此博客评论部分中提供的脚本,但它引发了以下错误:
Get-Package | Where Id -like "Contoso.*" | Sort-Object -Property Id -Unique | foreach { Update-Package $_.Id }
Where-Object : Cannot bind parameter 'FilterScript'. Cannot convert the "Id" value of type "System.String" to type "System.Management.Automation.ScriptBlock". At line:1 char:20 + Get-Package | Where <<<< Id -like "Contoso.*" | Sort-Object -Property Id -Unique | foreach { Update-Package $_.Id } + CategoryInfo : InvalidArgument: (:) [Where-Object], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.WhereObjectCommand
稍稍摆弄后,我认为我使用的是非常旧版本的PowerShell(v2.0),并且基于文档,以下脚本现在可以使用。我用Where-Object
替换Where
:
Get-Package | Where-Object {$_.Id -like "Contoso.*"} | Sort-Object -Property Id -Unique | foreach { Update-Package $_.Id }