Substring from Get-ChildItem RRS feed

  • Question

  • Hello all,

    I have to admit that I am a noob to Powershell, but love everything that you can do with it and do everything I can to automate all of our processes with Powershell.  We have to few hundred files a day that we process and need to log the files that are being processed.  I would like to create a log file that lists out the following fields:

     File Name, first 5 characters, characters 7-12

    24584-47962-01052015.pdf, 24584, 47962

    24585-47879-03022015.pdf, 24585, 47879

    24586-45059-04012015.pdf, 24586, 45059

    Here is what I have so far.

    $currentdate=get-date -DisplayHint Date -Format MMddyyy
    $test= Get-ChildItem -Path c:\temp -filter *.pdf|select name,basename.tostring.substring(0,5),basename.tostring.substring(7,5)
    $test|export-csv -path c:\temp\logs\$currentdate.csv

    Example of the file names:




    I assume that the basename is not a string so a substring will not work, but I cannot even get the basename.tostring to work.  How do I get it to string and then do a susbtring on the file names?

    Thanks in advance.

    Ross K

    • Edited by Krummie Thursday, May 7, 2015 3:28 PM
    Thursday, May 7, 2015 3:27 PM


All replies