I have multiple machines uploading files to one FTP directory. The first part of the filename is the machine, the rest is a timestamp, e.g. AAAAA_20130312_125113.
Now I want to get a sorted list of all Unique machines that have uploaded to this directory. I managed to write the lost of all filenames.substring(0,5) to the host but I still don't have the unique machine names.
$files=Get-ChildItem $strMOVETO -Name -Include TAS*.csv -Recurse
ForEach ($i in $files) { Write-Host $i.Substring(0,5) }
Any hints on how to do this? Does not necessary have to be a one liner, although that would be a nice challenge ;-).
Thanks!
pipe the results of your command into a
| sort -unique
...but better still would be to simplify the script...
What happens when you have an 8-character machine name? Your
substring
will break. Since the machine name, date & time are delimited by an_
, split on that & get the first item.To filter on date as well:
Not tested but something like this:
You don't need to do the Write-Host inside the loop and it's easier to use % instead of a foreach loop.