I’m using a script to move files from one directory to another. It’s also stripping out some text via some RegEx work. However, while I have a relatively short script, I think I can still do better. Below is my sample script.
$Source = "C:\temp\test\source"
$Dest = "C:\temp\test\dest"
get-childitem $Source\*.* | rename-item -newname {$_.name -replace '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}IP\.',''} -WhatIf
move-item $Source\*.* $Dest -WhatIf
Now, this works but, as you can see, it’s two lines and I’m pretty sure it can be done in one. I think I’m “not getting my money’s worth” out of the move-item command. How would I accomplish this without having to do a separate rename-item command? If you need more info, let me know and I’ll see what I can do. I’m rather new to PS and RegEx stuff. I deal more with batch files but I don’t think it can handle RegEx. That’s why I’m attempting PS.
You can use a regex replace on the destination parameter of the Move-Item cmdlet. That should do the job for you. Adapting your example: