Here’s a little POSH script I wrote today, generalized a bit.
The web part in question shows a list that has a column named “Title”, and one named “Percentage”, where it grouped them by a column called MarketType.
It started out sorting ascending by title, and afterwards sorts descending by percentage.
function global:Sort-WPBiggestPercentOnTop($SPViewUsedByWP)
{
$oldqu = $SPViewUsedByWP.Query
if $oldqu -ne "<GroupBy Collapse=""FALSE"" GroupLimit=""100""><FieldRef Name=""Market_x0020_Type"" Ascending=""FALSE"" /></GroupBy><OrderBy><FieldRef Name=""Title"" /></OrderBy>"
{ write-error "View not as expected"}
$newqu = $oldqu.Replace("<FieldRef Name=""Title"" />","<FieldRef Name=""Percentage"" Ascending=""FALSE"" />"
$SPViewUsedByWP.Query = $newqu
$SPViewUsedByWP.Update()
write-host "Need to reset the state of the web part toolbar, it gets changed when the view gets edited."
}