locked
Powershell looping and appending dates RRS feed

  • Question

  • I'm new to Powershell I have a folder with multiple files in upwards of 1200. I would like some help in writing a Powershell script that would loop through the folder and grab each file and using a command line upload tool, upload each file until lall files are uploaded.

    The files are in this format: filename120170501

    The script command goes like this:

    upload-utility uploadDataSetFile -said ************* -sas ****************** -sid ******************* –dsid FILE ID -sv 1 -fid FILE_1 -rl 20160316 -f filename120170501.txt -re ‘file description’

    So for each time the script makes a loop and grabs a file, I want it to append the date from the file to the filename in the script.

    Would really appreciate someone's help.
    Wednesday, May 31, 2017 5:26 PM

All replies

  • Use  command "Get-ChildItem folderpath -Recurse | select  Name"  to export all file names to a csv. And use that file in a for loop to get all files one by one.

    For example,

    import-csv filelist.csv | %{

     upload-utility uploadDataSetFile -said ************* -sas ****************** -sid ******************* –dsid FILE ID -sv 1 -fid FILE_1 -rl 20160316 -f $_.NAME -re ‘file description’

    }

    Note: %{} - is a short form of FOR loop.

    • Proposed as answer by S_K_P Friday, July 14, 2017 4:09 PM
    Friday, July 14, 2017 4:09 PM