The array class ha a static method to reverse arrays of any objects in PowerShell.
Syntax:
[array]::Reverse($ArrayToReverse)
Example
PS C:\> $Files = ls "C:\temp\ReverseTest\" PS C:\> $Files Directory: C:\temp\ReverseTest Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2/22/2022 3:36 PM 0 File 0.txt -a---- 2/22/2022 3:36 PM 0 File 1.txt -a---- 2/22/2022 3:36 PM 0 File 2.txt -a---- 2/22/2022 3:36 PM 0 File 3.txt -a---- 2/22/2022 3:36 PM 0 File 4.txt -a---- 2/22/2022 3:36 PM 0 File 5.txt -a---- 2/22/2022 3:36 PM 0 File 6.txt -a---- 2/22/2022 3:36 PM 0 File 7.txt -a---- 2/22/2022 3:36 PM 0 File 8.txt -a---- 2/22/2022 3:36 PM 0 File 9.txt PS C:\> [array]::Reverse($Files) PS C:\> $Files Directory: C:\temp\ReverseTest Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2/22/2022 3:36 PM 0 File 9.txt -a---- 2/22/2022 3:36 PM 0 File 8.txt -a---- 2/22/2022 3:36 PM 0 File 7.txt -a---- 2/22/2022 3:36 PM 0 File 6.txt -a---- 2/22/2022 3:36 PM 0 File 5.txt -a---- 2/22/2022 3:36 PM 0 File 4.txt -a---- 2/22/2022 3:36 PM 0 File 3.txt -a---- 2/22/2022 3:36 PM 0 File 2.txt -a---- 2/22/2022 3:36 PM 0 File 1.txt -a---- 2/22/2022 3:36 PM 0 File 0.txt PS C:\>
Comments