powershell - Move-item inside loop (one liner) -


i'm trying move files based on csv list. here's csv:

newalias,path tat000017.txt,tat000010.txt 

here's powershell:

import-csv tatlist.txt | foreach {move-item -path $_.path "new\"+$_.newalias} 

but error:

move-item : positional parameter cannot found accepts argument '+@{newalias=tat000017.txt; path=tat000010.txt}.newalias'.

at line:1 char:30

  • import-csv tatlist.txt | foreach {move-item -path $.path "new\"+$.newalias}
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • categoryinfo : invalidargument: (:) [move-item], parameterbindingexception
    • fullyqualifiederrorid : positionalparameternotfound,microsoft.powershell.commands.moveitemcommand

i'm running powershell in same directory tatlist.txt, files there in directory.

as per comment change to:

move-item -path $_.path "new\$($_.newalias)" 

you need notation $($myvariable.myproperty) having properties's variable expansion!


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -