Chained Rename-Item

Can the following be chained in some way? What would be the proper syntax?

get-childitem -Path .\*.txt | rename-item -NewName {{$_.name -replace "@{Name=",""} -and {$_.name -replace "}",""}}

Thank you


  • Edited by B3ach B0Y Thursday, September 03, 2015 6:29 PM
September 3rd, 2015 6:28pm

What exactly are you trying

Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 6:29pm

Ultimately I am trying to join these two statements:

get-childitem -Path .\*.txt | rename-item -NewName {$_.name -replace "@{Name=",""}
get-childitem -Path .\*.txt | rename-item -NewName {$_.name -replace "}",""}

September 3rd, 2015 6:45pm

Why?

Your file actually has '@{Name=' and '}' in it?

Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 6:46pm

get-childitem -Path .\*.txt |
       ForEach-Object{
           $newname= ($_.name -replace "???","???") -replace "}",""
          $_|rename-item -NewName $newname
}

September 3rd, 2015 6:46pm

The statement is removing unwanted test in the file name. The first line removes the "@{Name=" and the second removes the "}". Can both be done in one statement?
Free Windows Admin Tool Kit Click here and download it now
September 3rd, 2015 6:50pm

The statement is removing unwanted test in the file name. The first line removes the "@{Name=" and the second removes the "}". Can both be done in one statement?

Yes, see jrv's code.

I'd recommend fixing whatever process screwed up your original files in the first place.

September 3rd, 2015 6:51pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics