# Listing 5: FileNames3.ps1 # Retrieve the content from the batch file. # Assign the content to the $cmd variable. $cmd = get-content c:\scripts\filenames.cmd # Send the $cmd variable's output down the pipeline. # Remove the "@echo off" command. $cmd = $cmd | foreach-object { $_ -replace "@echo off", "" } # Run the batch command in $cmd. # Save the results to the $files variable. $files = cmd /c $cmd # Send the $files variable's output down pipeline. # Sort the files in descending order. $files | sort-object -descending | # Return the filename for "current" files. # Display the filename in uppercase letters. foreach-object {if ($_ -like "*current*.txt") {write-host $_.substring(16).toUpper()}}