Saravana
Saravana

Reputation: 40534

How to update all the NuGet packages in a solution starting with a particular name?

For example, I am looking for a command like this which will update only packages that start with the name PackagePrefix:

Update-Package "PackagePrefix.*"

I tried the script provided in the comments section of this blog, but it is throwing the following error:

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

Upvotes: 2

Views: 590

Answers (1)

Saravana
Saravana

Reputation: 40534

After fiddling around a little bit, I figured that I am using a very old version of Powershell (v2.0) and based on the documentation the following script works now. I replaced Where with Where-Object:

Get-Package | Where-Object {$_.Id -like "Contoso.*"} | Sort-Object -Property Id -Unique | foreach { Update-Package $_.Id }

Upvotes: 1

Related Questions