0

I have a script that displays changes from an array and an hashtable. The changes are displayed according to scriptnames or change dates.

When called from PS-concole I have the changes listed as dynamic parameters to make it easier to show specific date. But this list is in ascending order, thus 2019-12-30 comes before 2020-01-01. If there are many dates, the most recent will be far down in the bottom.

Is there a way to reverse the listing in descending order of this dynamic parameter?

EDIT This is the code creating the parameters:

[CmdletBinding()]

param ()

DynamicParam
{
    $ParamAttrib = New-Object System.Management.Automation.ParameterAttribute
    $AttribColl = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
    $AttribColl.Add($ParamAttrib)
    $AttribColl.Add((New-Object System.Management.Automation.ValidateSetAttribute($global:changeloghash.Keys)))
    $RuntimeParam = New-Object System.Management.Automation.RuntimeDefinedParameter('SkriptChanges',  [string], $AttribColl)

    $ParamAttrib2 = New-Object System.Management.Automation.ParameterAttribute
    $AttribColl2 = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
    $AttribColl2.Add($ParamAttrib2)
    $changeDates = @()
    $global:changeloghash.Values.GetEnumerator() | % {$_[0]} | select -Unique | % {$changeDates += $_}
    $AttribColl2.Add((New-Object System.Management.Automation.ValidateSetAttribute($changeDates)))
    $RuntimeParam2 = New-Object System.Management.Automation.RuntimeDefinedParameter('ChangeDatum',  [string], $AttribColl2)

    $RuntimeParamDic = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
    $RuntimeParamDic.Add('SkriptChanges', $RuntimeParam)
    $RuntimeParamDic.Add('ChangeDatum', $RuntimeParam2)

    return  $RuntimeParamDic
Smorkster
  • 322
  • 3
  • 10

1 Answers1

0

Yes, you would want to use the Sort-Object -Descending cmdlet. So your's might look something like this:

$myArray = $myArray | Sort-Object -Descending
Treasure Dev
  • 560
  • 4
  • 8
  • I have tried this in many forms and in different places, i.e. when fetching the dates, when adding to the array, when adding to ValidateSetAttribute, but nothing works. – Smorkster Jan 07 '20 at 13:39