none
How to code this powershell? RRS feed

  • Question

  • I would like to know on what wrong is following coding to rename item under powershell.

    Rename-Item "C:\Temp\" + (Get-Content 'C:\txt\yymmdd.txt') + ".csv" C:\Temp\ABC.csv

    Does anyone have any suggestions?
    Thanks in advance for any suggestions


    Thanks in advance for any suggestions

    Saturday, September 29, 2018 4:46 PM

Answers

All replies

  • You cannot rename the contents of a file.


    \_(ツ)_/

    Saturday, September 29, 2018 4:57 PM
  • C:\Temp\" + (Get-Content 'C:\txt\yymmdd.txt') + ".csv" should return "C:\Temp\180910.csv".

    so the task is as shown below, would it be possible to retrieve content and store in string variable before using Rename-Item.

    Rename-Item "C:\Temp\180910.csv" C:\Temp\ABC.csv

    Do you have any suggestions?
    Thank you very much for any suggestions (^v^)


    Thanks in advance for any suggestions

    Saturday, September 29, 2018 5:38 PM
  • $contents = Get-Content 'C:\txt\yymmdd.txt'

    Why?


    \_(ツ)_/

    • Marked as answer by oemMicrosoft Saturday, September 29, 2018 11:29 PM
    Saturday, September 29, 2018 5:44 PM
  • Thank you very much for suggestions (^v^)

    Thanks in advance for any suggestions

    Saturday, September 29, 2018 11:29 PM