1

rename-item A B

When typed in the shell, and provided there is a file A at the local directory, the rename works.

When I write a one-line script, put it in a folder, export the path to this folder, go to another folder, containing a file A, and call the script, here is what happens:

'rename-item' is not recognized as an internal or external command,
operable program or batch file.

What am I missing?

4
  • I suspect that you are trying to call the powershell script from a regular command prompt (cmd.exe) rather than from a powershell command prompt (powershell.exe) since that is the exact error that you would get in a regular command prompt.
    – EBGreen
    Commented Apr 9, 2013 at 15:17
  • @EBGreen, I am calling the file from a powershell. But the file is called rename.bat. Possibly this is my problem.
    – Vorac
    Commented Apr 9, 2013 at 15:19
  • 4
    That is definitely your problem. Rename it .ps1
    – EBGreen
    Commented Apr 9, 2013 at 15:22
  • @ EBGreen, Yey, one step further. Could you please write a short answer, explaining why the strange error message, so as to finish up this question nicely?
    – Vorac
    Commented Apr 9, 2013 at 15:25

1 Answer 1

2

When you ran the batch file, you were calling a batch file that had PowerShell commands in it. The command prompt was directing its output through Powershell, which was the above errors. Command.exe cannot run powershell cmdlets, so when it got to Rename-Item, it was not a good internal or external command, operable program or batch file.

Ping.exe is called when you Ping www.google.com for example of what is a good command or executable.

Powershell can run commands from command.exe, the reverse is not true.

You can see the same result if you open a cmd prompt and try to run powershell commands or cmdlets.:

H:\>rename-item 'rename-item' is not recognized as an internal or external command, 
operable program or batch file.
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.