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

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -