Calling a function within a Powershell Script

Started by bettman, August 19, 2023, 03:00:53 PM

Previous topic - Next topic

bettman

Greetings,

I have a powershell script which contains various functions, one of which is used to uninstall software. The command line to invoke this from a DOS batch file is as follows:

powershell.exe  -executionpolicy bypass-command "& { .'%~dp0Install_App.ps1'; UninstallApp }"

I have looked for a Winbatch example which describes how to do this but could not find one. I then thought of just invoking Powershell using Runwait (or something similar) but could not figure out how to format the bolded string section so Winbatch would accept it.

Any help would be appreciated.

td

There are multiple ways to properly escape the parameter line. Here is but one:

Code (winbatch) Select
str = "-executionpolicy bypass-command ""& { .'%%~dp0Install_App.ps1'; UninstallApp }"""
Message("Escaped Line", str)
exit




"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

A bug in the forum's WinBatch Script rendering extension converts single quotes to their HTML equivalent so the the '  sequence is actually a single quote. It should be the following:

"-executionpolicy bypass-command ""& { .'%%~dp0Install_App.ps1'; UninstallApp }"""
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade