I need to create scripts that manipulate files and their contents. If I use Windows Powershell, the following command perfectly works:
(Get-Content my_file.txt).Replace("aaa","bbb") | Set-Content my_file.txt
This command will replace any occurence of aaa by bbb. Yet, I would like to wrap this into a script file that I named rename.cmd. The content of the file is
CMD (Get-Content my_file.txt).Replace("aaa","bbb") | Set-Content my_file.txt
Now, if I type .\rename.cmd in PowerShell, I get the following error:
PS C:\Users\me\> .\rename.cmd
'Set-Content' is not recognized as an internal or external command,
operable program or batch file.
@%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Command "(Get-Content 'my_file.txt').Replace('aaa','bbb') | Set-Content 'my_file.txt'", or@%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Command "(Get-Content \"my_file.txt\").Replace(\"aaa\",\"bbb\") | Set-Content \"my_file.txt\"".