Call Powershell script from batch

My PS-script (simplified example) is:

write-Output "Test"
exit 5

I call this script from batch via:

powershell.exe -NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File c:\temp\test3.ps1
@echo ERRORLEVEL: %ERRORLEVEL% 

My questions are:

  • Where can I find information on -NoProfile -NoLogo -NonInteractive (I copied this from an example)? Do I need them?
  • Is there a way to transfer information (strings etc.) from PS to batch (and viceversa) other than by workfiles or registry (both not very efficient)?

Many thanks - Michael

PowerShell /?

I’d recommend to migrate all batch scripts you might still have to PowerShell as this is a way more modern, powerful and universal scripting environment.

Thanks! Do you recommend to use -NoProfile if one does nit use PS-Profiles?

I agree on using PS, but: I have a very huge batch-based system (ca. 500 KB of code/documentation) where migration would mean reprogramming with an effort of (estimated) 3 months. Thus I am struggling with a kind of smooth migration (programming new parts with PS, reprogramming part by part) which clarifies my need for information transfer.

Would you consider a kind of “transfer region” which is accessible by batch ans PS (eg a very simple database)?

Michael

That depends pretty much on your scripts. If there is nothing what needs the stuff you have in your profile you should use -NoProfile as this speeds up the PowerShell start.

I’d say it will be worth anyway and it shouldn’t take 3 month but at the end of the day it is your decision. :man_shrugging:t4:

Since PowerShell is way more advanced it should be significantly easier to get things done than with batch/CMD.

If you insist to have interactions between batch and PowerShell scripts I’d try to keep it as simple as possible. I’d probably use simple text files with the proper format like CSV, JSON, XML or even plain text files.

Thanks- I’ll think about it. Michael