我有一个脚本,显示来自数组和哈希表的更改。根据脚本名称或更改日期显示更改。
当从 PS-concole 调用时,我会将更改列为动态参数,以便更轻松地显示特定日期。但是这个列表是按升序排列的,因此 2019-12-30 在 2020-01-01 之前。如果有很多日期,则最近的日期将位于底部。
有没有办法按此动态参数的降序反转列表?
编辑 这是创建参数的代码:
[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