Skip to content

Instantly share code, notes, and snippets.

@HauptJ
Last active April 19, 2024 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HauptJ/7598d6de381dd063e9f5d36bf5513b9f to your computer and use it in GitHub Desktop.
Save HauptJ/7598d6de381dd063e9f5d36bf5513b9f to your computer and use it in GitHub Desktop.
Simple PowerShell Script with Arrays
$fileWordArray = [System.IO.File]::ReadAllLines("C:\Users\joshu\dev\temp\powershell\something.txt")
Write-Host "Begin: fileWordArray ----------------------------------------------------------------"
Write-Host $fileWordArray
Write-Host "Items in file: " $fileWordArray.Length
foreach ($word in $fileWordArray) {
Write-Host $word
}
Write-Host "End: fileWordArray ------------------------------------------------------------------"
Write-Host "Begin: sortedFileWordArray ----------------------------------------------------------------"
$sortedFileWordArray = $fileWordArray | Sort-Object
Write-Host $sortedFileWordArray
foreach ($word in $sortedFileWordArray) {
Write-Host $word
}
Write-Host "End: sortedFileWordArray ------------------------------------------------------------------"
Write-Host "Begin: sortedFileWordArrayDesc ----------------------------------------------------------------"
$sortedFileWordArrayDesc = $fileWordArray | Sort-Object -Descending
Write-Host $sortedFileWordArray
foreach ($word in $sortedFileWordArrayDesc) {
Write-Host $word
}
Write-Host "End: sortedFileWordArrayDesc ------------------------------------------------------------------"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment